Hello there!
I'm having a problem in my code. Can anyone help me, please?
What I'm trying to do is:
-I have a MySql database with a latitude and longitude columns
-I get the data from MySql with XML
-And I would like to do a reverse geocoding (get the address name from
the lat/lng point)
Its really simple I think. Look to my code:
--------------------------------------------------------------------------------------------------------------------
<script type="text/javascript">
var map;
var geocoder;
var address;
var dirn;
function initialize() {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(-23.5812,-46.7453), 15);
map.setUIToDefault();
geocoder = new GClientGeocoder();
dirn = new GDirections();
GDownloadUrl("xmlexport.php", function(data) {
var xml = GXml.parse(data);
var markers =
xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var point1 = new
GLatLng(parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
geocoder.getLocations(point1, function(result) {
if(result.Status.code != 200) {
document.getElementById("ruas").innerHTML+='coordinate: ' +
point1.toUrlValue() + ' refers to address: ' + 'reverse geocoder
failed to find an address <br />';
} else {
address =
result.Placemark[0];
document.getElementById("ruas").innerHTML+='coordinate: ' +
point1.toUrlValue() + ' refers to address: ' + address.address + '<br /
>';
}
});
}
});
}
</script>
--------------------------------------------------------------------------------------------------------------------
A example from my xml result:
--------------------------------------------------------------------------------------------------------------------
<markers>
<marker lat="-23.5812" lng="-46.7453"/>
<marker lat="-23.5812" lng="-46.7453"/>
<marker lat="-23.5812" lng="-46.7453"/>
<marker lat="-23.5812" lng="-46.7453"/>
<marker lat="-23.5812" lng="-46.7453"/>
</markers>
--------------------------------------------------------------------------------------------------------------------
Well, but inexplicably it doesn't work!
What I get is:
coordinate: -23.5812,-46.7453 refers to address: Av. Mal. Fiúza de
Castro, 415-627 - Butantã, São Paulo, 05596-000, Brasil
coordinate: -23.5812,-46.7453 refers to address: reverse geocoder
failed to find an address
coordinate: -23.5812,-46.7453 refers to address: Av. Mal. Fiúza de
Castro, 415-627 - Butantã, São Paulo, 05596-000, Brasil
Why some coordinate it works great, and another time, THE SAME
coordinate doesn't work?
--
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api?hl=en.