このコードで従来のマーカー機能を使用しようとしましたが、マーカーが表示されません。この情報ウィンドウにマーカーを追加するにはどうすればいいですか?このコードにマーカーを追加できません
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {
lat: 22.5726,
lng: 88.3639
},
zoom: 13
});
infoWindow = new google.maps.InfoWindow;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infoWindow.setPosition(pos);
infoWindow.setContent("You're here Bro!");
infoWindow.open(map);
map.setCenter(pos);
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
});
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}
new AutocompleteDirectionsHandler(map);
}
function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
infoWindow.open(map);
}
どこにマーカーのために追加したコードはありますか? –
投稿されたコードにマーカーを追加するものは何もありません。あなたは何をしましたか? – geocodezip
コードを使用しました - > var marker = new google.maps.Marker({ position:pos、 map:map、 }); - >前にinfoWindow =新しいgoogle.maps.InfoWindow;それはうまくいきませんでした –