问题描述
限时送ChatGPT账号..我想做的是创建应用程序,当任何人点击地图对象时,每次点击时两个字段都会填充纬度和经度.是否有 Google Maps V3 JavaScript API(地理编码 API)的示例代码可以做类似的事情?
What I would like to do is create app where when anyone clicks on the map object and two fields get filled with latitude and longitude at every click. Is there sample code of Google Maps V3 JavaScript API (Geocoding API) somewhere out there that does something like that?
推荐答案
您可以通过 google.maps.event' LatLng 属性:
You can achieve this with google.maps.event' LatLng property:
这样的东西会显示它是如何工作的.这是一个 JSFiddle 演示:
Something like this would show how it works. Here is a JSFiddle Demo:
google.maps.event.addListener(map, 'click', function(event){
alert('Lat: ' + event.latLng.lat() + ' Lng: ' + event.latLng.lng());
});
其中 map 是您的 google 地图对象.是的,我认为这个例子是在 V2 中,如果你想在点击时创建一个标记,你可以简单地在点击回调函数中创建它.
Where map is your google map object. Yes the example is in V2 i think, and if you would like to create a marker on click you can simply create it within the click callback function.
这篇关于纬度、经度抓取器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论