I am using google map API 3 and google geocoder. The problem is It’s not showing the marker and info window I am bringing the data by ajax and calling a function showAddress(elemId, address) Where elementId is div id where the map will be rendered. Here the code for the google map
<script type="text/javascript">
//<![CDATA[
var geocoder;
var map;
var lat;
var lng;
function showAddress(elemId, address) {
geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status){
// console.log(results[0].geometry.location.YA);
lat = results[0].geometry.location.Ya;
lng = results[0].geometry.location.Za;
var mapOptions = {
zoom: 15,
center: new google.maps.LatLng(lat, lng),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById(elemId),
mapOptions)
$('a#full-'+elemId).attr('href','http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q='+lat+','+lng+'')
var marker
marker = "marker_"+elemId;
myLatlng = new google.maps.LatLng(lat,lng);
marker = new google.maps.Marker({
id:elemId,
position: myLatlng,
map: map
});
var infowindow = "infowindow"+elemId;
infowindow = new google.maps.InfoWindow({
content: 'Hello world'
});
infowindow.open(map, marker);
google.maps.event.trigger(map, 'resize');
});
}
</script>
First of all .Ya and .Za are not documented properties so if you use them as in
that code is likely to break.
secondly, results[0].geometry.location is already a google.maps.LatLng() object, so there is no need to extract the lat and lng separately and create a new one. You can just use it like: