You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Occasionally my normally-working script will display this error: Fatal error: Call to undefined method Geocoder\Model\Address::getLatitude()
I'm using the dev-master version in Composer, but this didn't happen before today (I didn't modify my geocoder, though).
The error seems to occur randomly, about 1 in 20 times. Since it happens at that frequency I just get the feeling that some other function is trying to run and it couldn't wait for the Geocoder to finish. Upon refreshing the page the Geocoder and the rest of the script loads normally – every time.
If anyone has an idea on how to suppress the error so that the user doesn't get Fatal error I'd like to know some good ways to do that. I thought try {} catch() {} was supposed to do that.
The full code is
$geocoder = new \Geocoder\ProviderAggregator();
$adapter = new \Ivory\HttpAdapter\CurlHttpAdapter();
// a chain means it goes through the list until it can find a result
$chain = new \Geocoder\Provider\Chain([
new \Geocoder\Provider\BingMaps($adapter, $keys['bing']),
new \Geocoder\Provider\Nominatim($adapter, "http://nominatim.openstreetmap.org/search"),
new \Geocoder\Provider\MapQuest($adapter, $keys['mapquest'], true),
new \Geocoder\Provider\ArcGISOnline($adapter),
//new \Geocoder\Provider\GeocoderCaProvider($adapter, $geocoderCaKey), // geocoder-extra hasn't been updated
]);
$geocoder->registerProvider($chain);
try {
$geocode = $geocoder->geocode($q);
//($debug ? print_r2($geocode) : null);
if($version >= 3) {
$results['count'] = $geocode->count();
} else {
$results['count'] = 1;
}
if($results['count'] > 0) {
$results['chain'] = true;
$results['lat'] = $geocode->first()->getLatitudee();
$results['lng'] = $geocode->first()->getLongitude();
$results['zipcode'] = $geocode->first()->getPostalCode();
$results['address_raw'] = trim($geocode->first()->getStreetNumber()." ".$geocode->first()->getStreetName() );
$results['address'] = ucwords(strtolower(streetRename( $results['address_raw'] )));
$results['street_number'] = $geocode->first()->getStreetName();
$results['city'] = $geocode->first()->getLocality();
$results['state'] = $geocode->first()->getAdminLevels()->get(1)->getName();
$results['county'] = $geocode->first()->getAdminLevels()->get(2)->getName();
} else {
$results = false;
}
} catch (Exception $e) {
($debug ? print_r("Geocoder had an exception") : null );
($debug ? print_r2($e->getMessage()) : null );
$results = false;
}
The text was updated successfully, but these errors were encountered:
Hard to debug. It seems that, sometimes, your collection of results is empty, hence the null value returned by first(). I fixed the code to avoid such a situation.
Occasionally my normally-working script will display this error:
Fatal error: Call to undefined method Geocoder\Model\Address::getLatitude()
I'm using the
dev-master
version in Composer, but this didn't happen before today (I didn't modify my geocoder, though).The error seems to occur randomly, about 1 in 20 times. Since it happens at that frequency I just get the feeling that some other function is trying to run and it couldn't wait for the Geocoder to finish. Upon refreshing the page the Geocoder and the rest of the script loads normally – every time.
If anyone has an idea on how to suppress the error so that the user doesn't get
Fatal error
I'd like to know some good ways to do that. I thoughttry {} catch() {}
was supposed to do that.The full code is
The text was updated successfully, but these errors were encountered: