Closed ghost closed 5 years ago
You are calling getLatitude()
on $geocoder
(the actual geocoder) rather than the result ($geocode
in your case).
Use:
$lat = $geocode->getLatitude();
$long = $geocode->getLongitude();
You are calling
getLatitude()
on$geocoder
(the actual geocoder) rather than the result ($geocode
in your case).Use:
$lat = $geocode->getLatitude(); $long = $geocode->getLongitude();
<?php
require_once('vendor/autoload.php');
ini_set('display_errors', 'On');
use GuzzleHttp\Client as GuzzleClient;
use Geocoder\Provider\GoogleMaps;
use Http\Adapter\Guzzle6\Client;
use Geocoder\Query\GeocodeQuery;
use Geocoder\Query\ReverseQuery;
$apikey = 'AIzaSyBbiute7hwz_ESi3U75ETeRwgnjfceZm3s';
$httpClient = new \Http\Adapter\Guzzle6\Client();
$provider = new \Geocoder\Provider\GoogleMaps\GoogleMaps($httpClient, 'Brazil', $apikey);
$geocoder = new \Geocoder\StatefulGeocoder($provider, 'BR');
$enderecos = array(
array(
'endereco' => 'RUA CAIGANGUES N:136 '
),
array(
'endereco' => 'R:DA AURORA N45',
),
array(
'endereco' => 'R:LUIZ LONE N110',
),
array(
'endereco' => ' R:JOAO DA LAPRIA N543 ',
)
);
foreach ($enderecos as $key=>$value) {
try {
$geocode = $geocoder->geocode($value['endereco']);
$lat = $geocode->getLatitude();
$long = $geocode->getLongitude();
} catch(Exception $e) {
echo $e->getMessage();
}
}
Im still getting the error: Uncaught Error: Call to undefined method Geocoder\Model\AddressCollection::getLatitude()
Please @maschinedreams , read the documentation : https://github.com/geocoder-php/Geocoder#statefulgeocoder
Please @maschinedreams , read the documentation : https://github.com/geocoder-php/Geocoder#statefulgeocoder
I dont know how to do this, I just need to get all their coordinates, can you hhelp me?
use Geocoder\Query\GeocodeQuery;
// configure your provider
$provider = // ...
$geocoder = new \Geocoder\StatefulGeocoder($provider);
$results = $geocoder->geocodeQuery(GeocodeQuery::create('London'));
foreach ($results as $result) {
$lat = $result->getLatitude();
$lng = $result->getLongitude();
}
or something like that. or using a dumper.
Im trying to put addressess in an array, and making a conditional for the geocoding of those locations which where gave me. How could I fetch them from the BD and iterate and display their lat and long?