Google map APIでマーカー(アイコン)を好きな画像に変える
2024/04/18
Googleマップでユーザーにマーカー画像をアップロードさせて、それをマップ表示時に出したいというケースがあった。以下にソースコードをメモ。
ソースコード
function makeMarker( addressArray ){
var marker = new google.maps.Marker({
position : new google.maps.LatLng(addressArray.x,addressArray.y),
map: map
<?php if( $accocuntData['icon'] != '' && file_exists(ICON_PATH . $accocuntData['icon']) ){?>,icon: '<?=ICON_URL . $accocuntData["icon"]?>'<?php } ?>//ここでアイコン指定
});
var addressArray;
var infoWindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker, 'click', function() {
if (currentWindow) {
currentWindow.close();
}
infoWindow.setContent('<a href="detail.php?e='+addressArray.id+'&f=<?=$jsQuery?>">'+addressArray.name+'</a>');
infoWindow.open(map,marker);
currentWindow = infoWindow;
});
}
関連記事
-
-
GoogleMapAPIのジオコードで存在するはずの住所が見つからない場合の原因について(ZERO_RESULTS)
GoogleMapAPIを利用したプログラムで確かに存在するはずの住所をジオコー ...
-
-
GoogleMapAPIでクリックした座標にマーカーを設置する方法
GoogleMapAPIでクリックした位置にマーカーを設置し、座標の経度緯度をテ ...
-
-
GoogleMapAPIで住所・経度緯度入力後にマーカーを移動させる
フォーム内に住所・経度・緯度のテキストボックスを設置し、住所を入力後にボタンを押 ...
-
-
Google Maps APIで現在地取得と目的地までのルートを表示させる方法
Google Maps APIを使って現在地を取得しつつ、目的地までのルートを表 ...
-
-
androidでgeolocationを使うとtimeoutになる
Geolocation APIを用いて現在地をGoogleMapに表示させるとい ...