Google Maps HTML5 click to get lat, long

后端 未结 3 974
一生所求
一生所求 2020-12-25 11:23

I\'m trying to build a mobile HTML5 webapp in which user can click on the map to get lat/long from Google Maps. Is there a code example? I tried googling but only found some

3条回答
  •  梦谈多话
    2020-12-25 11:49

    You have to use event argument.

     google.maps.event.addListener(map, 'click', function(event) {
         marker = new google.maps.Marker({position: event.latLng, map: map});
         console.log(event.latLng);   // Get latlong info as object.
         console.log( "Latitude: "+event.latLng.lat()+" "+", longitude: "+event.latLng.lng()); // Get separate lat long.
     });
    

提交回复
热议问题