Forked from: yd_niku's ReverseGeocodingTest diff(8) use bounds args - ReverseGeocodingTest mash Follow 2010-09-02 17:44:59 License: MIT License Fork1 Fav1 View1086 bounds つけて領域を絞り込めばより詳細な結果を返してくれそうだ Play Stop Reload Fullscreen Smart Phone Fork tree Readme JavaScript 98 lines HTML 4 lines CSS 2 lines bounds つけて領域を絞り込めばより詳細な結果を返してくれそうだ use bounds args - ReverseGeocodingTest jQuery v1.4.2 // bounds つけて領域を絞り込めばより詳細な結果を返してくれそうだ // とれなかったらboundsをもっと狭い範囲にすればよさげ // forked from yd_niku's "ReverseGeocodingTest" http://jsdo.it/yd_niku/sLQV /* 「新宿」とか「自由が丘」のような地名を取得するために 地図の中心逆ジオコーディングすると 地名リストがすべて郵便番号レベルでしか取れないケースがあります。 便番号のLocationで再度逆ジオコーディングするといいと書いてあるものもありますが どうやらすべてがうまくいくわけではないようです。 特に東京駅がうまくいかないんですが、なにか確実に地名を取る方法がありますでしょうか? */ // まずはGoogleMapsを生成 var latlng = new google.maps.LatLng(35.6816935,139.7690112); var myOptions = { zoom: 15, center: latlng, navigationControl:false, mapTypeControl:false, scaleControl:false, streetViewControl:false, scrollwheel:false, disableDoubleClickZoom:true, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById("map-container"),myOptions); // ボタン押すと逆ジオコーディング開始 $('#getReverseGeocoding').click(function(){ geocoding(); }); // 逆ジオコーディング処理本体 var geocoder = new google.maps.Geocoder(); function geocoding() { geocoder.geocode({ latLng:map.getCenter(), language: "ja", region: "JP", bounds: map.getBounds() }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { //取得成功した場合 var newAddress; var priorityMap = []; //結果の中からなるべく好ましいのを選ぶよ for(i=0; i<results.length; i++){ switch(results[i].types[0]){ case 'locality': priorityMap[0] = results[i]; break; case 'sublocality_level_1': priorityMap[1] = results[i]; break; case 'sublocality_level_2': priorityMap[2] = results[i]; break; case 'sublocality_level_3': priorityMap[3] = results[i]; break; case 'sublocality_level_4': priorityMap[4] = results[i]; break; case 'sublocality_level_4': priorityMap[4] = results[i]; break; } } //一番いいのを抽出 for( i=0; i< priorityMap.length; ++i ) { if( priorityMap[i] ) { newAddress = priorityMap[i].formatted_address; break; } } if(newAddress){ //有効な地名が含まれていた場合 $('#place').text(newAddress); } else{ //郵便番号しか含まれてなかった場合場合 alert("Reverse Geocoding is failed."); if(console)console.log(results); } } else { //取得失敗した場合 alert("Geocoder failed due to: " + status); } }); } <script src="http://maps.google.com/maps/api/js?sensor=true&language=ja"></script> <div id="map-container" style="width:400px;height:350px"></div> <p id="getReverseGeocoding">地名取得</p> <p id="place"></p> use bounds args - ReverseGeocodingTest body { background-color: #DDDDDD; font: 12px sans-serif; } #getPos, #getReverseGeocoding{ border:1px solid #333; background-color:#fff; width:120px; } bounds つけて領域を絞り込めばより詳細な結果を返してくれそうだ // bounds つけて領域を絞り込めばより詳細な結果を返してくれそうだ // とれなかったらboundsをもっと狭い範囲にすればよさげ // forked from yd_niku's "ReverseGeocodingTest" http://jsdo.it/yd_niku/sLQV /* 「新宿」とか「自由が丘」のような地名を取得するために 地図の中心逆ジオコーディングすると 地名リストがすべて郵便番号レベルでしか取れないケースがあります。 便番号のLocationで再度逆ジオコーディングするといいと書いてあるものもありますが どうやらすべてがうまくいくわけではないようです。 特に東京駅がうまくいかないんですが、なにか確実に地名を取る方法がありますでしょうか? */ // まずはGoogleMapsを生成 var latlng = new google.maps.LatLng(35.6816935,139.7690112); var myOptions = { zoom: 15, center: latlng, navigationControl:false, mapTypeControl:false, scaleControl:false, streetViewControl:false, scrollwheel:false, disableDoubleClickZoom:true, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById("map-container"),myOptions); // ボタン押すと逆ジオコーディング開始 $('#getReverseGeocoding').click(function(){ geocoding(); }); // 逆ジオコーディング処理本体 var geocoder = new google.maps.Geocoder(); function geocoding() { geocoder.geocode({ latLng:map.getCenter(), language: "ja", region: "JP", bounds: map.getBounds() }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { //取得成功した場合 var newAddress; var priorityMap = []; //結果の中からなるべく好ましいのを選ぶよ for(i=0; i<results.length; i++){ switch(results[i].types[0]){ case 'locality': priorityMap[0] = results[i]; break; case 'sublocality_level_1': priorityMap[1] = results[i]; break; case 'sublocality_level_2': priorityMap[2] = results[i]; break; case 'sublocality_level_3': priorityMap[3] = results[i]; break; case 'sublocality_level_4': priorityMap[4] = results[i]; break; case 'sublocality_level_4': priorityMap[4] = results[i]; break; } } //一番いいのを抽出 for( i=0; i< priorityMap.length; ++i ) { if( priorityMap[i] ) { newAddress = priorityMap[i].formatted_address; break; } } if(newAddress){ //有効な地名が含まれていた場合 $('#place').text(newAddress); } else{ //郵便番号しか含まれてなかった場合場合 alert("Reverse Geocoding is failed."); if(console)console.log(results); } } else { //取得失敗した場合 alert("Geocoder failed due to: " + status); } }); } <script src="http://maps.google.com/maps/api/js?sensor=true&language=ja"></script> <div id="map-container" style="width:400px;height:350px"></div> <p id="getReverseGeocoding">地名取得</p> <p id="place"></p> body { background-color: #DDDDDD; font: 12px sans-serif; } #getPos, #getReverseGeocoding{ border:1px solid #333; background-color:#fff; width:120px; } use an iframe compat browser, deer Tweet QR code Embed Design view Code view <script type="text/javascript" src="http://jsdo.it/blogparts/3OyU/js?view=design"></script><p class="ttlBpJsdoit" style="width: 465px; margin: 0; text-align: right; font-size: 11px;"><a href="http://jsdo.it/mash/3OyU" title="use bounds args - ReverseGeocodingTest">use bounds args - ReverseGeocodingTest - jsdo.it - share JavaScript, HTML5 and CSS</a></p> zip tags google-maps Tweet twitter Tags google-maps Favorite by kotobuki Forked sort new page view favorite forked forked: use bounds args - Reve.. mattari_pand.. 00 57views 101/4/2 google-maps forked from: use bounds args -.. drapon 00 337views 18/5/2