javascript 谷歌地图信息窗口位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16295228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 04:06:32 来源:igfitidea点击:
Google Maps Infowindow Position
提问by anderskristo
I have a problem with this code, when i click on a marker I want the infowindow to open up at that marker's position.
我有这个代码的问题,当我点击一个标记时,我希望信息窗口在该标记的位置打开。
When i click on every marker they all open up on the same position.
当我点击每个标记时,它们都在同一位置打开。
code:
代码:
App.map = function (data, cb) {
App.getData(App.config.LFMurl(), function (data) {
App.processData(data, function(arr){
var mapOptions = {
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions)
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude)
var marker
$.each(arr, function (index, item) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(item.lat, item.long),
map: map,
animation: google.maps.Animation.DROP
})
google.maps.event.addListener(marker, 'click', function(){
var infowindow = new google.maps.InfoWindow({
map: map,
position: new google.maps.LatLng(item.lat, item.long),
content: item.title
})
infowindow.open(map, this)
console.log(item.artist)
})
})
map.setCenter(pos)
}, function() {
handleNoGeolocation(true)
})
} else {
handleNoGeolocation(false) // Browser som inte st?djer geolocation
}
})
})
}
回答by anderskristo
Got it to work...
得到它的工作...
at the bottom i did this:
在底部我这样做了:
infowindow.open(map, this)
changed 'this' with 'marker'
用“标记”改变了“这个”