Javascript google map API在每次渲染时都向远标记移动(似乎是随机的)
我制作了一个使用谷歌地图API V3的应用程序。我设置了一个Javascript google map API在每次渲染时都向远标记移动(似乎是随机的),javascript,google-maps,google-maps-api-3,meteor,Javascript,Google Maps,Google Maps Api 3,Meteor,我制作了一个使用谷歌地图API V3的应用程序。我设置了一个 myLatlng = new google.maps.LatLng(22.26, 114.19) 这是香港的某个地方。这是在Meteor.JS中的render中设置的,所以每次您进入该页面时,它都应该进入该位置。但问题是,我把它部署到了网上,并开始和朋友们一起玩这个应用程序。当有人把一个别针放在屏幕外面或远离香港的初始位置时,每当人们再次渲染该页面时,地图就向远处的PIN拉去。有人知道我为什么和如何解决这个问题吗?我现在不想做地理定
myLatlng = new google.maps.LatLng(22.26, 114.19)
这是香港的某个地方。这是在Meteor.JS中的render中设置的,所以每次您进入该页面时,它都应该进入该位置。但问题是,我把它部署到了网上,并开始和朋友们一起玩这个应用程序。当有人把一个别针放在屏幕外面或远离香港的初始位置时,每当人们再次渲染该页面时,地图就向远处的PIN拉去。有人知道我为什么和如何解决这个问题吗?我现在不想做地理定位,我以后会把它作为一个按钮功能来做
这是我的密码:
makeModal = (marker, nameObject)->
google.maps.event.addListener marker, "click", ->
Crater.overlay "profilepop",
data:
nameObject
arrayOfMarkers = []
Template.map.rendered = ->
if !Meteor.user()
$('#map-canvas').attr("title", "sign in to add your pin!")
Crater.dismissOverlay('.crater-overlay')
GoogleMaps.init
sensor: true #optional
key: gmapskey #optional
# language: "de" #optional
, ->
myLatlng = new google.maps.LatLng(22.26, 114.19)
mapOptions =
zoom: 13
mapTypeId: google.maps.MapTypeId.ROADMAP
center: myLatlng
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions)
google.maps.event.addListener map, "click", (e) ->
placeMarker e.latLng, map
updateThis =
"profile.lat": e.latLng.k
"profile.long": e.latLng.B
currentTarget = Meteor.userId()
Meteor.call 'updateThis' ,updateThis, currentTarget, (error, result) ->
listOfUsers = Meteor.users.find().fetch()
arrayOfMarkers = []
for i in [0...listOfUsers.length]
if listOfUsers[i].profile.lat != null
thisLocation = new google.maps.LatLng(listOfUsers[i].profile.lat, listOfUsers[i].profile.long)
marker = new google.maps.Marker(
id: listOfUsers[i]._id
title: listOfUsers[i].profile.name
position: thisLocation
map: map
icon: listOfUsers[i].profile.picturesquare
)
mapinfo = "hi"
name = listOfUsers[i].profile.name
nameObject = listOfUsers[i]
contentStr = "<div style='height:auto, width:auto'>#{name}</div>"
infowindow = new google.maps.InfoWindow(content: contentStr)
infowindow.open(map, marker)
arrayOfMarkers.push(marker)
makeModal marker, nameObject
console.log arrayOfMarkers
placeMarker = (position, map) ->
##add if statement for people adding forr the first time
if Meteor.user().profile.lat == null
else
oldPin = _.find(arrayOfMarkers, (x) ->
x.id == Meteor.user()._id
)
oldPin.setMap(null)
oldPin = null
arrayOfMarkers = _.filter(arrayOfMarkers, (x) ->
x.id != Meteor.user()._id
)
marker = new google.maps.Marker(
id: Meteor.user()._id
position: position
map: map
animation: google.maps.Animation.DROP
icon: Meteor.user().profile.picturesquare
)
mapinfo = "hi"
name = Meteor.user().profile.name
picLink = Meteor.user().profile.picture
contentStr = "<p>#{name}</p>"
infowindow = new google.maps.InfoWindow(content : contentStr)
infowindow.open(map, marker)
arrayOfMarkers.push(marker)
google.maps.event.addListener marker, "click", ->
infowindow.open map, marker
makeModal marker, Meteor.user()
把这个放在你申报地图之后
map.setCentermyLatlng 您的应用程序中有一个bug。没有看到代码就无法调试。谢谢。我在编辑中添加了代码