need some help with this one.
I'm using Google Maps API v3 to grab the latitude and longitude of human readable addresses stored in my database, then placing 1 marker on a Google Map canvas. Pretty straightforward.
The problem I'm experiencing is that some addresses are kicking back a status code of --> ZERO_RESULTS
If I type these same addresses into maps.google.com they will find that specific area and map it with a marker with an approximation.
Some of the addresses I have in my database are not specific, meaning they may not have a Postal Code and/or they may not have a City, but all have a Province/Region and Country. Also important to note is that none of them have a Street Address.
Some of the human readable addresses may have dashes (-), spaces ( ), apostrophes ('), and commas(,)
An example of an address that is kicking back ZERO_RESULTS is:
Soul-t'ukpyolsi, Korea, South
In that specific example, the Country has a comma and space in the name, and also the Region has an apostrophe and a dash.
Here is the Javascript code I'm using:
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&key=MYKEY&sensor=false"></script>
<script>
function initialize() {
var myLatlng = new google.maps.LatLng(<?php echo $lat; ?>,<?php echo $long; ?>);
var mapOptions = {
zoom: 5,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
I'm using PHP to generate the full address path based on address elements stored in my database. Here is the code I'm using to generate the path and then issue the geolocator request:
Remember that City and Postal Code/Zip are optional elements
// Replace any spaces in vars
if (isset($gmaps_city)){
$gmaps_city = str_replace(" ","+",$gmaps_city);
}
if (isset($gmaps_province)){
$gmaps_province = str_replace(" ","+",$gmaps_province);
}
if (isset($gmaps_country)){
$gmaps_country = str_replace(" ","+",$gmaps_country);
}
if (isset($gmaps_pcode)){
$gmaps_pcode = str_replace(" ","+",$gmaps_pcode);
}
// If Postal Code and City
if (isset($gmaps_city) AND isset($gmaps_pcode)){
$gmaps_path = $gmaps_city.",+".$gmaps_province.",+".$gmaps_country.",+".$gmaps_pcode."&sensor=false";
// If City but no Postal Code
} else if (isset($gmaps_city) AND !isset($gmaps_pcode)){
$gmaps_path = $gmaps_city.",+".$gmaps_province.",+".$gmaps_country."&sensor=false";
// If Postal Code but no City
} else if (!isset($gmaps_city) AND isset($gmaps_pcode)){
$gmaps_path = $gmaps_province.",+".$gmaps_country.",+".$gmaps_pcode."&sensor=false";
// Only Province and Country
} else {
$gmaps_path = $gmaps_province.",+".$gmaps_country."&sensor=false";
}
// Determine Lat and Long of Address
$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$gmaps_path);
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;
$status = $output->status;
Any help is greatly appreciated.
The example might be causing issues because of a misspelling. The following: "Seoul-t'ukpyolsi, Korea, South" Does not return ZERO_RESULTS.
The dashes and apostrophes should not cause problems based on your code. Please provide another example.