Reputation: 77
I have made a map in google maps api v3 and trying to apply reverse geocoding on map but i failed to load my map with geocoding map.When I run the map maps shows but no marker shows on map.Here is My Map link and code as also
hers is Map code
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
var script = '<script type="text/javascript" src="js/cluster';
if (document.location.search.indexOf('compiled') !== -1) {
script += '_compiled';
}
script += '.js"><' + '/script>';
document.write(script);
</script>
<script type="text/javascript">
google.load('maps', '3', {
other_params: 'sensor=false'
});
google.setOnLoadCallback(initialize);
var markerClusterer = null;
var map = null;
var geocoder;
var markers = new Array();
function initialize() {
var GPS = [
{GPS:new google.maps.LatLng(34.019626247176,71.57975666079601), CNT:'Pakistan',REGION:'Peshawar',DIST:'Furqan Enterprises',SHOP:'Jamal Sweets',OWNER:'Ibrar Khan',MOBILE:'0300 989 9008',REGNO:'0000001',ICON:'1.png'},
{GPS:new google.maps.LatLng(34.02025371621,71.579215441513), CNT:'Pakistan',REGION:'Peshawar',DIST:'Furqan Enterprises',SHOP:'Usman Medicoz',OWNER:'Usman Hussain',MOBILE:'0344 905 1231',REGNO:'0000002',ICON:'1.png'},
];
geocoder = new google.maps.Geocoder();
var map_center = new google.maps.LatLng(31.2330555556,72.3330555556);
var myOptions = {
zoom: 6,
scaleControl:true,
pancontrol: true,
streetViewControl: true,
center: map_center,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map"), myOptions);
var infowindow = new google.maps.InfoWindow();
if (markerClusterer) {
markerClusterer.clearMarkers();
}
for(i=0; i<GPS.length; i++)
{
geocoder.geocode({'latLng': GPS[i].GPS}, function(results, status) {
//map.setZoom(11);
var markerImage = new google.maps.MarkerImage(imageUrl,
new google.maps.Size(24, 32));
var imageUrl = 'ico/' + GPS[i].ICON;
markers[i] = new google.maps.Marker({
position: GPS[i].GPS,
draggable: true,
icon: markerImage,
Info: '<table frame=box><tr><td align="Left"><font face="Arial" size=2 color=#336699>Shop Name:</td><td align="Left"><font face="Arial" size=2>'+ GPS[i].SHOP + '</font></td></tr><tr>'+
'<td align="Left"><font face="Arial" size=2 color=#336699>Owner:</td><td align="Left"><font face="Arial" size=2>'+ GPS[i].OWNER + '</font></td></tr>'+
'<td align="Left"><font face="Arial" size=2 color=#336699>Mobile:</td><td align="Left"><font face="Arial" size=2>'+ GPS[i].MOBILE + '</font></td></tr>'+
'<tr><td align="Left"><font face="Arial" size=2 color=#336699>Distributer:</td><td align="Left"><font face="Arial" size=2>'+ GPS[i].DIST + '</font></td></tr><tr>'+
'<tr><td align="Left"><font face="Arial" size=2 color=#336699>Region:</td><td align="Left"><font face="Arial" size=2>'+ GPS[i].REGION + '</font></td></tr>'+
'<tr><td align="Left"></td><td align="Left"><font face="Arial" size=2 color=#336699><a target=_blank href=http://221.120.216.52/elp/sfpl.php?ccode=01&®no='+ GPS[i].REGNO +'>View</a></td></tr>'+
'<tr><td align="Left"><font face="Arial" size=2 color=#336699>Region:</td><td align="Left"><font face="Arial" size=2>'+ results[1].formatted_address + '</font></td></tr>'+
'</table>',
title:GPS[i].SHOP + '(' +GPS[i].DIST + ')'
});
markers.push(markers);
google.maps.event.addListener(markers[i], 'click', function() {
infowindow.setContent(this.Info);
infowindow.open(map,this);
});
});
}
zoom = -1 ? null : -1;
size = -1 ? null : -1;
markerClusterer = new MarkerClusterer(map, markers, {
maxZoom: zoom,
gridSize: size
});
}
</script>
Any One Please help me to display the Nearest Address of coordinates on infowindow.
Upvotes: 0
Views: 499
Reputation: 12983
Reverse geocoding doesn't work in every country. See the list of functionality coverage provided by Google.
If "Geocoding" says "same as tiles" then only locations identified on the tiles can be geocoded, and reverse geocoding is also limited. Google don't have full details of everywhere in that country.
This applies to Pakistan.
It's also the case that you are not checking the status returned by the geocoder. It gets passed to the callback function and you never use it. It will almost certainly give some hint about what's going on.
Upvotes: 1