纬度,经度捕捉器 [英] Latitude, Longitude Grabber

查看:115
本文介绍了纬度,经度捕捉器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是创建应用程序,当任何人点击地图对象时,每次点击时两个字段都会填充经度和纬度。是否有谷歌地图V3 JavaScript API(Geocoding API)的示例代码在那里做类似的事情?

通过 google.maps.event 实现此目的LatLng属性:



像这样的东西会显示它的工作原理。这是一个 JSFiddle演示:

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

其中map是您的Google地图对象。是的,我想V2中的例子是,如果你想在点击时创建一个标记,你可以简单地在点击回调函数中创建它。


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?

解决方案

You can achieve this with google.maps.event' LatLng property:

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());
});

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆