点击获取GOOGLE MAP地图上的经纬度坐标的方法

来源:互联网 发布:阿曼达.诺克斯 知乎 编辑:程序博客网 时间:2024/05/17 09:08
 

GOOGLE  map api让我们可以在自己的网站上显示GOOGLE MAP 那样强大的功能,只要你编程够牛逼,数据库数据多。你的GOOGLE MAP会比GOOGLE 的MAP更牛。万丈高楼平地起,以下是通过点击获取GOOGLE map地图上的经纬度的方法。

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>点击获取GOOGLE  MAP地图上的经纬度坐标的方法</title>
<script src=”http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAjKcjb95IlYLFHhr2ekAEOhS6HVL9N0Eta0oPyPTncBECn8JwShSB34ymWvKJRvBNpjpCQCezykCWYA”
  type=”text/javascript”></script>
<script type=”text/javascript”>
function initialize() {
  if (GBrowserIsCompatible()) {
  var map = new GMap2(document.getElementById(“map_canvas”));
  map.setCenter(new GLatLng(34.45221847282654,106.69921875), 4);
  map.setUIToDefault();
  }
    GEvent.addListener(map, ‘click’, function(overlay, point) {
  if (overlay) {
   // nothing
  } else {
    //清除以前所点击图标
    map.clearOverlays();
    document.getElementById(“jingwei”).value = point.y + “,” + point.x;
    var marker = map.addOverlay(new GMarker(point));
  }
 });
}
</script>

</head>
<!–打开网页的时候载入initialize()函数–>
<body onload=”initialize()” onunload=”GUnload()”>
<div id=”map_canvas” style=”width: 800px; height: 600px”></div>
<input name=”officename” type=”text” id=”jingwei”  />
</body>
</html>

注意以上代码必须是UTF-8下才能得到正确的结果。

文章来自熙煦阳光的博客,转载请注明出处

链接地址http://www.uibao.com/archives/142