PALMisLIFE 討論區

搜索
鹹魚爸魅力四射舞蹈教室
查看: 65813|回復: 0
打印 上一主題 下一主題

如何在 Google Map 上擷取得地標經緯度

[複製鏈接]

90

主題

0

好友

623

積分

  • TA的每日心情
    無聊
    2011-6-9 21:02
  • 簽到天數: 1 天

    連續簽到: 1 天

    [LV.1]初來乍到

    文章
    388
    1#
    發表於 2009-3-11 18:49 |顯示全部樓層
    根據之前試的結果要點到沒道路的地方才行
    不過有時候google map 會幫忙選到附近的大景點
    這個方法就沒辦法用(ex.台北車站附近就很難點)

    有興趣的話可以用google map提供的api自己寫一個html把滑鼠點到的座標點秀出來
    把下面的code copy 到notepad 之類的編輯軟體
    存檔成 *.html (ex. test.html)
    用firefox開就可以了 (ie 應該不行)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
      <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <title>Google Maps JavaScript API Example: Map Markers</title>
        <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=rtdrtgsdfgdsfgsdfgdfgdfsgsd"
                type="text/javascript"></script>
        <script type="text/javascript">

        var map = null;
       
        function initialize() {


          if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map_canvas"));
                map.addControl(new GLargeMapControl());                 //加入地圖縮放工具
                map.addControl(new GMapTypeControl());                 //加入地圖切換的工具
                map.addMapType(G_PHYSICAL_MAP);                         //加入地形圖

            map.setCenter(new GLatLng(25.0806,121.564702), 13); // center of map
            var blueIcon = new GIcon(G_DEFAULT_ICON);
            blueIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";

            GEvent.addListener(map,"click", function(overlay,latlng) {
              if (overlay) {
                // ignore if we click on the info window
                return;
              }
              var tileCoordinate = new GPoint();
              var tilePoint = new GPoint();
              var currentProjection = G_NORMAL_MAP.getProjection();
              tilePoint = currentProjection.fromLatLngToPixel(latlng, map.getZoom());
              tileCoordinate.x = Math.floor(tilePoint.x / 256);
              tileCoordinate.y = Math.floor(tilePoint.y / 256);
              var myHtml = "Latitude: " + latlng.lat() + "<br/>Longitude: " + latlng.lng() +
                "<br/>The Tile Coordinate is:<br/> x: " + tileCoordinate.x +
                "<br/> y: " + tileCoordinate.y + "<br/> at zoom level " + map.getZoom();       
              map.openInfoWindow(latlng, myHtml);
            });


          }
        }

        </script>
      </head>

      <body onload="initialize()" onunload="GUnload()">
        <div id="map_canvas" style="width: 800px; height: 480px"></div>
      </body>
    </html>

    不然直接去demo裡面找應該也可以找到類似的sample code.
    回復

    使用道具 舉報

    您需要登錄後才可以回帖 登錄 | 免費註冊

    與站長聯繫| PALMisLIFE 掌上生活      下載:更快、更棒、更好玩

    GMT+8, 2024-6-2 08:30 , Processed in 0.040082 second(s), 30 queries , Gzip On.

    Powered by Discuz!

    © 2001-2012 Comsenz Inc. style by eisdl

    回頂部