Google maps v3 geocode multiple custom markers by address or latlng -
i need plot multiple custom map markers using mapsv3 api either address or lat/lon. put following code works ok lon/lat, if data contains address geocoder returns nothing. ideas on how fix this.
$(document).ready(function () { initialize(); }); function initialize() { var centermap = new google.maps.latlng(-27.0,133.0); var options = { pancontrol: false, zoomcontrol: true, scalecontrol: false, maptypecontrol: false, streetviewcontrol: false, zoom: 3, center: centermap, maptypeid: google.maps.maptypeid.roadmap } var map = new google.maps.map(document.getelementbyid("map"), options); var data = [ { 'title':'f c building construction ...', 'address':'', 'zindex':20, 'lat':'-33.797847', 'lon':'151.259928', 'marker_number':1, 'marker_html':' html content...', 'image': { url:'//localhost/assets/images/markers/marker_1.png', size: new google.maps.size(24, 29), origin: new google.maps.point(0,0), anchor: new google.maps.point(10, 29) } }]; setmarkers(map, data); var infowindow = new google.maps.infowindow(); } function showmappin(i) { } function setmarkers(map,data) { var bounds = new google.maps.latlngbounds(); (var = 0; < data.length; i++) { setmarker(map, data[i], bounds); } map.fitbounds(bounds); } function setmarker(map, m, bounds) { if(m["address"]!="") { var geocoder = new google.maps.geocoder(); geocoder.geocode( { "address": m["address"] }, function(results, status) { if (status == google.maps.geocoderstatus.ok) { var sitelatlng = results[0].geometry.location; } }); } else { var sitelatlng = new google.maps.latlng(m["lat"], m["lon"]); } if(sitelatlng) { var marker = new google.maps.marker({ position: sitelatlng, map: map, //shadow: shadow, icon: m["image"], title: m["title"], zindex: m["zindex"], html: m["marker_html"] }); bounds.extend(sitelatlng); google.maps.event.addlistener(marker, "click", function() { infowindow.setcontent(this.html); infowindow.open(map, this); }); } // if latlng }//]]>
after looking on code realized variable sitelatlng within geocode function scope never gets passed , can't returned. setting marker within function works.
Comments
Post a Comment