Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.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 主干Js-设置地理位置变量[未定义的变量]_Javascript_Html_Backbone.js_Geolocation - Fatal编程技术网

Javascript 主干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');

我试图设置一个变量来保存要在Google地图上绘制的纬度和经度变量(我试图稍后将其设置为可以添加到集合中)。我正在运行控制台长测试,发现我的函数中的变量正在设置坐标。我怎样才能做到呢?(对不起,我对JavaScript和Backbone.Js还是新手)


猜测:问题似乎出在
这个
引用上

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');
    }
},