谷歌地图API移动到远标记在每次渲染(似乎随机)
google map API moves toward far marker on every render (seems random)
我制作了一个使用Google Maps API V3的应用程序。我设置了一个位置
myLatlng = new google.maps.LatLng(22.26, 114.19)
在香港的某个地方。这是在"渲染"中设置的(在Meteor.JS中),所以每次你进入那个页面时,它都应该去那个位置。但问题是,我把它放到了网上,开始和我的朋友们玩这个应用。当有人在屏幕外或离初始位置(香港)很远的地方放置一个大头针时,每次人们再次渲染页面时,地图都会拉向那个遥远的大头针。有人知道为什么和如何解决这个问题吗?我现在不想做地理定位,我以后会把它作为一个按钮函数。
下面是我的代码: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声明之后
map.setCenter(myLatlng);
相关文章:
- 如何在JS中随机化backgroundPosition而不使用鼠标移动来制作万花筒的动画
- 随机jquery移动/角度内部错误与安卓浏览器
- 如何在Javascript中在桌子周围随机移动图像
- 使用单选按钮使 Div 在页面上随机移动
- 如何让 Div 使用单选按钮随机移动
- 不透明度+随机移动的随机计时
- 使用JavaScript和html将图像和超链接从一个位置随机移动到另一个位置
- 鼠标下移页面X,页面Y和鼠标移动页面X后页面Y不一样,随机发生
- 一些潜水器的起始位置和随机移动
- 如何让数组对象随机移动
- 用鼠标移动随机放置的盒子
- 如何移动一个图像随机当你点击另一个图像使用html &javascript
- 谷歌地图API移动到远标记在每次渲染(似乎随机)
- 使用原型继承模式的随机移动动画
- Kineticjs:画布中图像的随机移动动画
- 精灵图像的随机移动位置
- 使图像随机移动,点击
- 从Javascript中的坐标随机移动
- 随机移动的图像被屏幕的左上角吸引
- 在固定区域中随机移动图像