google maps - Get latitude and longitude of marker (onclick) of already exist place (already marked) place -
i m using google map api lat long on click event.i'm able lat long on click when tries click place exist or having marked on place doesn't allow me click on place or on text or icon near text. attaching image .
this code lat long
google.maps.event.addlistener(map, "click", function (e) { removemarkers(null); var latlng = e.latlng; var lat1 = e.latlng.lat(); var lng1 = e.latlng.lng(); updatelatlongboxes(lat1, lng1); // place marker on clicked position var marker = new google.maps.marker({ position: latlng }); marker.setmap(map); //store current marker in array markers.push(marker); });
google maps triggers own click handler poi objects , there no official way register custom event.
probably the preferable approach here hide poi features via styles shown below
function initmap() { var latlng = new google.maps.latlng(40.713638, -74.005529); var myoptions = { zoom: 17, center: latlng, maptypeid: google.maps.maptypeid.roadmap, styles: [{ featuretype: "poi", elementtype: "labels", stylers: [{ visibility: "off" }] }] }; var map = new google.maps.map(document.getelementbyid("map_canvas"), myoptions); google.maps.event.addlistener(map, "click", function (event) { //console.log(event.latlng.tostring()); placemarker(map, event.latlng); }); } function placemarker(map, location) { var marker = new google.maps.marker({ position: location, map: map }); } google.maps.event.adddomlistener(window, 'load', initmap);
#map_canvas { height: 600px; width: 800px; }
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <div id="map_canvas"></div>
another option register custom click handler overriding google.maps.infowindow
demonstrated below:
function initmap() { var latlng = new google.maps.latlng(40.713638, -74.005529); var myoptions = { zoom: 17, center: latlng, maptypeid: google.maps.maptypeid.roadmap }; var map = new google.maps.map(document.getelementbyid("map_canvas"), myoptions); google.maps.event.addlistener(map, "click", function (event) { //console.log(event.latlng.tostring()); placemarker(map, event.latlng); }); var fnsetcontent = google.maps.infowindow.prototype.setcontent; google.maps.infowindow.prototype.setcontent = function () { google.maps.event.addlisteneronce(this, 'map_changed', function () { var map = this.getmap(); google.maps.event.trigger(map, 'click', { latlng: this.getposition() }); this.close(); //force close info window }); fnsetcontent.apply(this, arguments); }; } function placemarker(map, location) { var marker = new google.maps.marker({ position: location, map: map }); } google.maps.event.adddomlistener(window, 'load', initmap);
#map_canvas { height: 600px; width: 800px; }
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <div id="map_canvas"></div>
Comments
Post a Comment