gpt4 book ai didi

javascript - 使用 Meteor 在 map 上获取当前位置

转载 作者:行者123 更新时间:2023-11-30 00:26:40 26 4
gpt4 key购买 nike

嘿,我正在使用 dburles:mapsmdg:geolocation 这两个包,我的目标是在 map 上绘制当前位置。这是我当前显示 map 的 JS 代码,但我不确定如何处理它。

map .js已编辑

Meteor.startup(function() {
GoogleMaps.load();
});

Template.map.helpers({
mapOptions: function() {
if (GoogleMaps.loaded()) {
return {
center: new google.maps.LatLng(current),
zoom: 8
};
}
}
});

Template.map.onCreated(function() {
GoogleMaps.ready('map', function(map) {

if (navigator.geolocation) {
// Support
navigator.geolocation.getCurrentPosition(function(position) {
var current = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
});
map.setCenter(current);
} else {
// No support
console.log("Something is wrong!")
}

})
})

我想我应该在 if(navigator.geolocation 中添加一些内容,然后将值放在 center: new google.maps.LatLng() 中,但不确定。有什么想法吗?

最佳答案

Meteor.startup(function() {
GoogleMaps.load({v: '3', key: 'yourKey'});
});

var latLng;

Template.map.onCreated(function() {
GoogleMaps.ready('map', function(map) {
});
});

Template.map.helpers({
mapOptions: function() {
if (GoogleMaps.loaded()) {
latLng = Geolocation.latLng();
console.log('location ' + latLng.lat + ' ' + latLng.lng);
return {
center: new google.maps.LatLng(latLng.lat, latLng.lng),
zoom: 14
};
}
}
});

关于javascript - 使用 Meteor 在 map 上获取当前位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31169497/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com