Last active
August 29, 2015 13:57
-
-
Save lunaluna/9701886 to your computer and use it in GitHub Desktop.
【Javascript】PHPから渡された緯度・経度の値からGoogleMapを描画する【WordPress】
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var map; | |
// 緯度を変数に代入 | |
var latitude = Number("<?php echo $latitude; ?>"); | |
// 経度を変数に代入 | |
var longitude = Number("<?php echo $longitude; ?>"); | |
// 倍率を変数に代入 | |
var magnification = Number("<?php echo $map_magnification; ?>"); | |
// 目的地を地図が描画される中心に設定する | |
var centerPosition = new google.maps.LatLng(latitude, longitude); | |
function initialize() { | |
var mapOptions = { | |
zoom: magnification, //縮尺(0に近いほど広範囲を表示) | |
center: centerPosition, //地図の中心座標 | |
mapTypeId: google.maps.MapTypeId.ROADMAP //地図の種類を指定 | |
}; | |
map = new google.maps.Map(document.getElementById('map_area'), mapOptions); | |
// マーカー追加 | |
var marker = new google.maps.Marker({ | |
position: centerPosition, //マーカーを表示させる座標 | |
map: map, //マーカーを表示させる地図 | |
title : "<?php echo $map_marker; ?>" //マウスオーバーした際に表示させる文字列 | |
}); | |
} | |
google.maps.event.addDomListener(window, 'load', initialize); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment