差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

兩邊的前次修訂版 前次修改
start:google:maps [2009/12/14 14:24] jonathanstart:google:maps [2009/12/14 14:25] (目前版本) jonathan
行 1: 行 1:
 +====== Google 地圖找座標 ======
 +<html>
 +  <head> 
 +    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
 +    <title>Google Maps JavaScript API Example: Reverse Geocoder</title> 
 +    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAVVIaGcLI-3o-sANr9O-SqhQ7itgXKq2lOUhGp3-InRmgyDBLgBSpMZMUuDJ32UnqyGhfuyTo83Ucnw" 
 +            type="text/javascript"></script> 
 +    <script type="text/javascript"> 
 + 
 +    var map;
 +    var geocoder;
 +    var address;
 + 
 +    function initialize() {
 +      map = new GMap2(document.getElementById("map_canvas"));
 +      map.setCenter(new GLatLng(25.046412,121.537031), 15);
 +      map.setUIToDefault();
 +      GEvent.addListener(map, "click", getAddress);
 +      geocoder = new GClientGeocoder();
 +    }
 +    
 +    function getAddress(overlay, latlng) {
 +      if (latlng != null) {
 +        address = latlng;
 +        geocoder.getLocations(latlng, showAddress);
 +      }
 +    }
 + 
 +    function showAddress(response) {
 +      map.clearOverlays();
 +      if (!response || response.Status.code != 200) {
 +        alert("Status Code:" + response.Status.code);
 +      } else {
 +        place = response.Placemark[0];
 +        point = new GLatLng(place.Point.coordinates[1],
 +                            place.Point.coordinates[0]);
 +        marker = new GMarker(point);
 +        map.addOverlay(marker);
 +        marker.openInfoWindowHtml(
 +        '<b>orig latlng:</b>' + response.name + '<br/>'
 +        '<b>latlng:</b>' + place.Point.coordinates[1] + "," + place.Point.coordinates[0] + '<br>' +
 +        '<b>Status Code:</b>' + response.Status.code + '<br>' +
 +        '<b>Status Request:</b>' + response.Status.request + '<br>' +
 +        '<b>Address:</b>' + place.address + '<br>' +
 +        '<b>Accuracy:</b>' + place.AddressDetails.Accuracy + '<br>' +
 +        '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
 +      }
 +    }
 + 
 + 
 +    </script> 
 +  </head> 
 + 
 +  <body onload="initialize()"> 
 +    <div id="map_canvas" style="width: 500px; height: 400px"></div> 
 +  </body> 
 +</html>