Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Meteor获取地图上的当前位置_Javascript_Google Maps Api 3_Meteor - Fatal编程技术网

Javascript 使用Meteor获取地图上的当前位置

Javascript 使用Meteor获取地图上的当前位置,javascript,google-maps-api-3,meteor,Javascript,Google Maps Api 3,Meteor,嘿,我正在使用两个包dburles:maps和mdg:geolocation,我的目标是在地图上绘制当前位置。这是我当前的JS代码,显示的是一个地图,但我不知道如何继续 map.js 已编辑 Meteor.startup(function() { GoogleMaps.load(); }); Template.map.helpers({ mapOptions: function() { if (GoogleMaps.loaded()) { return {

嘿,我正在使用两个包
dburles:maps
mdg:geolocation
,我的目标是在地图上绘制当前位置。这是我当前的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
中添加一些内容,然后将值放在
中心:new google.maps.LatLng()
,但不确定。有什么想法吗?

你说得对。你看到了吗?

这有帮助吗?没有,我不是为android平台制作的,而是一个web应用程序。我已经看了一段时间了,但我感到困惑,因为有一些东西是按照不同的顺序定义的。考虑到地图包,我更新了我的code、 这在大致范围内,但还不完全在那里。
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
        };
    }
  }
});