Google Maps HTML5 click to get lat, long

后端 未结 3 959
一生所求
一生所求 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:55

    I want to show you complete answere:

    this is main part of the code the event is based on click and get Lat/Long with click and show it at alert()

    google.maps.event.addListener(map, 'click', function(event) { alert(event.latLng.lat() + ", " + event.latLng.lng()); });

    
    
    
    

    please change your API KEY

    src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBu-916DdpKAjTmJNIgngS6HL_kDIKU0aU&callback=myMap"

    put your API KEY between key= and &callback:

    https://maps.googleapis.com/maps/api/js?key= @@@@@@@ &callback=myMap

提交回复
热议问题