google地图获取经度、纬度

使用javaScript获取经度、纬度

源代码:

<!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 runat="server">
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Google 地图 JavaScript API 示例</title>
    <style type="text/css">
        v/:*
        {
            behavior: url(#default#VML);
        }
    </style>

    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true_or_false&amp;key=ABQIAAAAEzBcFHJG5Mdd3tVrDkw1OxQ9ZMENm1LAhaifwVnEkDLWfHJVgBR7IxJ7DBbtJCr7Y-uoV23JvDLiYQ"
        type="text/javascript"></script>

    <script type="text/javascript">
        //<![CDATA[
        function load() {
            //创建地图
            var map = new GMap(document.getElementById("map"));
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
           
            var customUI = map.getDefaultUI();
            customUI.maptypes.hybrid = true;
            map.centerAndZoom(new GPoint(106, 33), 14);

            GEvent.addListener(map, 'click', function(overlay, point) {
                if (point != undefined) {
                    var latLngStr = '经度:' + point.x + '<br/>纬度:' + point.y + '';
                    map.openInfoWindowHtml(point, latLngStr);
                    var newpoint = new GLatLng(point.y, point.x);
                    var polyline = new GPolyline([oldpoint, newpoint], "#FF0000", 2);
                    map.addOverlay(polyline);
                    oldpoint = newpoint;
                }
            });
            var oldpoint =new GLatLng(30.6586020, 104.0648570);
           
            ////30.6586020,104.0648570 ;30.65578187269602,104.08275604248047
            map.setCenter(new GLatLng(30.6586020, 104.0648570), 13);
//            var polyline = new GPolyline([
//    new GLatLng(30.6586020, 104.0648570),
//    new GLatLng(30.65578187269602, 104.08275604248047)
//], "#FF0000", 2);
//            map.addOverlay(polyline);

        }
        //]]>
    </script>

</head>
<body onload="load()" onunload="GUnload()">
    <form id="form1" runat="server">
    <div id="map" style="width: 500px; height: 300px">
    </div>
    <span id="message"></span>
    </form>
</body>
</html>

运行结果如图:

你可能感兴趣的:(google地图获取经度、纬度)