点击Google地图坐标信息窗口 [英] Google map coordinates info window on click

查看:137
本文介绍了点击Google地图坐标信息窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何让默认的Google地图界面在用户点击地图时在信息窗口中显示长和长的坐标吗?

Does anyone know how make the default Google map interface display long and lat coordinates in an info window when the user clicks on the map?

标题代码:

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key=..." type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
    map.setCenter(new GLatLng(13.175771, -59.556885), 10);
    map.setUIToDefault();
  }
}
</script>

正文代码:

<div id="map" style="width: 640px; height: 300px"></div>


推荐答案

 google.maps.event.addListener(map, 'click', function(event) {
    new google.maps.InfoWindow({
      position: event.latLng,
      content: event.latLng.toString() 
    }).open(map);
 });

这篇关于点击Google地图坐标信息窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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