谷歌地图HTML5点击获取经纬度 [英] Google Maps HTML5 click to get lat, long

查看:446
本文介绍了谷歌地图HTML5点击获取经纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建移动HTML5网络应用,其中用户可以点击地图从Google地图获取经纬度。有代码示例吗?我尝试了谷歌搜索,但只发现了一些网站,但没有soucecode的例子。

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 website that does that but no soucecode example.

这是因为我要使用HTML5地理位置来显示当前位置,但如果它不准确,那么用户可以自己指定。

This is because I'm going to use HTML5 geolocation to display the current location first, but if it's not accurate then users can specify that by themselves.

非常感谢。

推荐答案

下面的代码会显示给您如何在用户点击地图时获取Long和Lat - 允许用户在Google地图上放置标记

The code below will show you how to get the Long and Lat when the user clicks the map - Allow user to place marker on a google map

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

这篇关于谷歌地图HTML5点击获取经纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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