Javascript 主干Js-设置地理位置变量[未定义的变量]
我试图设置一个变量来保存要在Google地图上绘制的纬度和经度变量(我试图稍后将其设置为可以添加到集合中)。我正在运行控制台长测试,发现我的函数中的变量正在设置坐标。我怎样才能做到呢?(对不起,我对JavaScript和Backbone.Js还是新手)Javascript 主干Js-设置地理位置变量[未定义的变量],javascript,html,backbone.js,geolocation,Javascript,Html,Backbone.js,Geolocation,我试图设置一个变量来保存要在Google地图上绘制的纬度和经度变量(我试图稍后将其设置为可以添加到集合中)。我正在运行控制台长测试,发现我的函数中的变量正在设置坐标。我怎样才能做到呢?(对不起,我对JavaScript和Backbone.Js还是新手) 猜测:问题似乎出在这个引用上 将getLocation方法更新如下: getLocation: function(){ var self = this; console.log('Test - getGeolocation');
猜测:问题似乎出在
这个
引用上
将getLocation
方法更新如下:
getLocation: function(){
var self = this;
console.log('Test - getGeolocation');
if(navigator.geolocation){
//navigator.geolocation.getCurrentPosition(this.setLatLng);
navigator.geolocation.getCurrentPosition(function (position) {
self.setLatLng(position);
});
}else{
alert('Either you have no internet connection or your browser is not supported');
}
},
Test - getGeolocation Area.js:32
undefined undefined - Confirmed Area.js:13
Test - setLatLng Area.js:42
Test - setLatLng-lat Area.js:44
Test - setLatLng-lng Area.js:46
19.7180872 -89.0860836
getLocation: function(){
var self = this;
console.log('Test - getGeolocation');
if(navigator.geolocation){
//navigator.geolocation.getCurrentPosition(this.setLatLng);
navigator.geolocation.getCurrentPosition(function (position) {
self.setLatLng(position);
});
}else{
alert('Either you have no internet connection or your browser is not supported');
}
},