Google Geocoder ignora el país en la dirección buscada

This is the issue: a user chooses a hotel name, city and country, and that location is found using Google Places so that a marker can be added to a Google Map.

City and country are concatenated into a variable named $code (separated by comma) which is searched for in this way:

function getLatLong($code){
$code=str_replace(" ", "+", $code);
$query = "".$code."&sensor=false";
$data = file_get_contents($query);
// if data returned
    // convert into readable format
    $data = json_decode($data);
    $long = $data->results[0]->geometry->location->lat;
    $lat = $data->results[0]->geometry->location->lng;
    return array('Latitude'=>$lat,'Longitude'=>$long);
    return false;

The returned lat/lng pair is then used to center the search area for the hotel name. However, the Geocoder seems to completely disregard the country, so if $code="San Jose, Costarica" it only searches for 'San Jose' and returns San Jose, California!

This is a huge problem as there are many cities that share names, especially in South America.

Since this is a world-wide search, creating coordinate polygons for every country is out of the question.

Anyone have a solution for this issue?

preguntado el 09 de marzo de 12 a las 14:03

Poniendo "San Jose, Costa Rica" in $code in your example query URL returns hits from San Jose (and other places) in Costa Rica. Maybe it's just because "Costarica" isn't a country? -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.