郵便番号から、緯度経度をもとめて、地図の真ん中に設定したいです。
2015/07/05
api
googleapi
map
google map apiです。
郵便番号から、緯度経度をもとめて、地図の真ん中に設定したいです。
コードはかなりわかってないです。
下記のコードは、いろいろ試行錯誤した結果です。
<script type="text/javascript">
var map;
function initialize() {
var mapOptions = {
center: { lat: -34.397, lng: 150.644},
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
function show01() {
var p = document.getElementById('postalCode');
var pcode = p.value;
var geocoderCallback = function( results, status ) {
if( status == google.maps.GeocoderStatus.OK ) {
var movePos = results[0].geometry.location;
console.log(movePos);
map.setCenter(movePos);
} else { alert(status);
}
};
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': pcode
, 'componentRestrictions':{'country':'jp'}
, 'language':'ja', 'region': 'JP'}
, geocoderCallback);
}
</script>
: