Google Map API (6) 搜尋
Posted In:
Google Map
.
By 卡西卡
關鍵:GClientGeocoder, getLocations
展示:http://klcintw.googlepages.com/google-map-GClientGeocoder.htm
<!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">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps (台灣)</title>
<script src="http://maps.google.com/maps?file=api&v=2&key="
type="text/javascript" for="http://klcintw.googlepages.com"></script>1:
2: <script type="text/javascript">3: //<![CDATA[4: var map = null;5: var geocoder = null;6: function load() {7: // 檢查瀏覽器是否可使用 Google Map API8: if ( GBrowserIsCompatible() ) {9: map = new GMap2(document.getElementById("map"));10: geocoder = new GClientGeocoder();11:
12: // 設定地圖中心點13: map.setCenter(new GLatLng(25.036772,121.520269), 14);14: } // if15: }
16:
17: // showLocation() is called when you click on the Search button18: // in the form. It geocodes the address entered into the form19: // and adds a marker to the map at that location.20: function showLocation() {21: var address = document.forms[0].q.value;22: geocoder.getLocations(address, addAddressToMap);
23: }
24:
25: // addAddressToMap() is called when the geocoder returns an26: // answer. It adds a marker to the map with an open info window27: // showing the nicely formatted version of the address and the country code.28: function addAddressToMap(response) {29: map.clearOverlays();
30: if (!response || response.Status.code != 200) {31: alert("查無資料!\n Sorry, we were unable to geocode that address");32: } // if33: else {34: place = response.Placemark[0];
35: point = new GLatLng(place.Point.coordinates[1],36: place.Point.coordinates[0]);
37: marker = new GMarker(point);38: map.addOverlay(marker);
39: marker.openInfoWindowHtml(place.address + '<br>' +40: '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);41: } // else42: }
43:
44: // findLocation() is used to enter the sample addresses into the form.45: function findLocation(address) {46: document.forms[0].q.value = address;
47: showLocation();
48: }
49: //]]>50:
</script>
</head>
<body onload="load()" onunload="GUnload()">
<h1>GClientGeocoder</h1>
<form action="#" onsubmit="showLocation(); return false;">
<p>
<b>地址:</b>
<input type="text" name="q" value="古亭國小" class="address_input" size="40" />
<input type="submit" name="find" value="Search" />
</p>
</form>
<div id="map" style="width:500px; height:350px"></div>
<ul>
<li><a href="javascript:findLocation('台北市羅斯福路三段201號');">古亭國小(以地址尋找)</a></li>
<li><a href="javascript:findLocation('古亭國小');">古亭國小(以名稱尋找)</a></li>
</ul>
</body>
</html>
4 Responses to Google Map API (6) 搜尋
請問可以做個利用setTimeout做多筆資料輪流顯示的範例嗎?類似地圖日記那樣!
請問一下
class = address_input
要怎麼查裡面的變數與函式用法呢
不好意思 還是新手
請多包涵
謝謝你
curry 6
jordan shoes
coach outlet online
nike air max 97
yeezy boost 350 v2
nike shoes
yeezys
golden goose
golden goose
yeezy boost 350 v2
Something to say?