Extjs 获取要放置在代理中的地理位置变量

Extjs 获取要放置在代理中的地理位置变量,extjs,sencha-touch-2,Extjs,Sencha Touch 2,我正在尝试将设备的当前位置添加到代理调用中。我已经添加了带有“+radius+”和“+values+”的变量。我使用了Ext.util.Geolocation,可以在控制台中看到地理位置。如何从中获取lat和long变量,以便添加到代理中,如“+lat+”和“+lon+” Ext.define('FirstApp.controller.History', { extend:'Ext.app.Controller', config:{ refs:{ main:'main'

我正在尝试将设备的当前位置添加到代理调用中。我已经添加了带有“+radius+”和“+values+”的变量。我使用了Ext.util.Geolocation,可以在控制台中看到地理位置。如何从中获取lat和long变量,以便添加到代理中,如“+lat+”和“+lon+”

Ext.define('FirstApp.controller.History', {
extend:'Ext.app.Controller',

config:{
    refs:{
        main:'main',
        placesContainer:'placesContainer',
        placesList:'placesContainer places list',
        info:'info',
        review:'review',
        rss:'rss',
        favourites:'favourites',
        mapcontainer:'mapcontainer',
        visit: '#visit',
        radius: '#radius'
    },
    control:{
        'placesContainer places list':{
            itemtap:'recordDetailsNavigation'
        },
        'main':{
            activeitemchange:'recordTabChanged'
        },
         '#home': {
            // On the tap event, call onNewTap
            tap: 'onHomeTap'
        },
          '#info': {
            // On the tap event, call onNewTap
            tap: 'onInfoTap'
        }
        ,
          '#search': {
            // On the tap event, call onNewTap
            tap: 'onSearchTap'
        }
          ,
          '#leaveReview': {
            // On the tap event, call onNewTap
            tap: 'onReviewTap'
        }

    },
    routes: {
        'placesContainer': 'gotoPlacesContainer',
        'placesContainer/:id': 'gotoPlacesContainerDetails',
        'info': 'gotoInfo',
        'review': 'gotoReview',
         'rss': 'gotoRss',
        'favourites': 'gotoFavourites',
        'mapcontainer': 'gotoMapContainer'
    }
     },
     recordDetailsNavigation:function (list, index, target, record) {
    console.log("recordDetailsNavigation");
    this.getApplication().getHistory().add(Ext.create('Ext.app.Action', {
        url:'placesContainer/' + record.get('id')
    }),true);
    },
    recordTabChanged:function(tab,value, oldValue){
    console.log("recordTabChanged "+value.xtype);
    this.getApplication().getHistory().add(Ext.create('Ext.app.Action', {
        url:value.xtype
    }),true);
     },


gotoPlacesContainer:function(){
    console.log('Goto PlacesContainer');
    this.getMain().setActiveItem(0);
    var items = this.getPlacesContainer().getItems();
    console.log("PlacesContainer has "+items.length+" children")
    if(items.length>1){
        this.getPlacesContainer().pop();
    }


},

gotoReview:function(){
    console.log('Goto Review');
    this.getMain().setActiveItem(1);
     Reviews.load();
},


gotoMapContainer:function(){
    console.log('Goto MapContainer');
    this.getMain().setActiveItem(2);
},

gotoPlacesContainerDetails:function(id){
    console.log('Goto PlacesContainer Details for id '+id);

    this.gotoPlacesContainer();
    this.getPlacesList().refresh();
    this.getPlacesList().on('refresh',function(){
        var store = Ext.getStore('Places');
        var index = store.find('id',id);
        var record = store.getAt(index)
        this.getPlacesContainer().push({
            xtype:'details',
            title:record.data.name,
            data:record.data
        })
        this.getApplication().getHistory().add(Ext.create('Ext.app.Action', {
            url:'placesContainer/' + record.get('id')
        }),true);
    },this);

},

  gotoInfo:function(){
    console.log('Goto Info');
    this.getMain().setActiveItem(3);
},

    gotoRss:function(){
    console.log('Goto Rss');
    this.getMain().setActiveItem(4);
},


gotoFavourites:function(){
    console.log('Goto Favourites');
    this.getMain().setActiveItem(5);
},


 onHomeTap: function() {

    Ext.Viewport.setActiveItem(Ext.create('FirstApp.view.Home'));
},

 onReviewTap: function() {

    Ext.Viewport.setActiveItem(Ext.create('FirstApp.view.CreateReview'));
},

  onInfoTap: function() {
    Ext.Viewport.setActiveItem(Ext.create('FirstApp.view.Info'));
},

  onSearchTap: function() {

    Ext.Viewport.setActiveItem(Ext.create('FirstApp.view.Main'));

    var values = this.getVisit().getValue();
     var radius = this.getRadius().getValue() * 1000;

    console.log(values);
    console.log(radius);

    var proxy = {
    type:'ajax',
    id:'myPlaceProxy',
    url:'https://maps.googleapis.com/maps/api/place/search/json?    location=52.247983,-7.141113&radius='+radius+'&types='+values+'&name=&sensor=false&key=',
    reader:{
        type:'json',
        rootProperty:'results'
    }
    }


   var geo = new Ext.util.Geolocation({
    autoUpdate: false,
    allowHighAccuracy: true,
    listeners: {
    locationupdate: function(geo) {
       lat = geo.getLatitude();
       lon = geo.getLongitude();
       var proxy = Ext.getCmp('myPlaceProxy');
       proxy.setUrl('https://maps.googleapis.com/maps/api/place/search/json?location='+lat+','+lon+'&radius='+radius+'&types='+values+'&name=&sensor=false&key=AIzaSyAAStZvDJ_5ENODEdSCanLWgJBG6p6eXBQ');
       console.log(proxy);
       Ext.StoreMgr.get('Places').setProxy(proxy);
       Ext.StoreMgr.get('Places').load();    
    }
    }
   });

  geo.updateLocation();
  }


});


Ext.define('FirstApp.store.Places',{
extend:'Ext.data.Store',

config:{

    autoLoad:false,
    model:'FirstApp.model.Place',
    proxy:{


    }
}
})

首先,给你的代理提供id,这样我们就可以随时通过id访问它

var proxy = {
        type:'ajax',
        id:'myPlaceProxy',
        url:'https://maps.googleapis.com/maps/api/place/search/json?location=52.247983,-7.141113&radius='+radius+'&types='+values+'&name=&sensor=false&key=',
        reader:{
            type:'json',
            rootProperty:'results'
        }
    }
然后在地理位置的locationupdate事件中访问代理

var geo = new Ext.util.Geolocation({
    autoUpdate: true,
    allowHighAccuracy: true,
    listeners: {
        locationupdate: function(geo) {
           lat = geo.getLatitude();
           lon = geo.getLongitude();
           var proxy = Ext.getCmp('myPlaceProxy');
           proxy.setUrl('https://maps.googleapis.com/maps/api/place/search/json?location='+lat+','+lon+'&radius='+radius+'&types='+values+'&name=&sensor=false&key='');
           console.log(proxy);
           Ext.StoreMgr.get('Places').setProxy(proxy);
           Ext.StoreMgr.get('Places').load();    
        }
    }
});
然后在需要时通过调用此

geo.updateLocation();
编辑:

但我强烈建议不要总是制造风险 您只需调用这个geo.updateLocation();一旦您在全球范围内创建它,您就可以更好地管理它

试试这个:

Ext.define('FirstApp.store.Places',{
extend:'Ext.data.Store',
id: 'myPlaces',
config:{

    autoLoad:false,
    model:'FirstApp.model.Place',
    proxy:{
        type:'ajax',
        url:'https://maps.googleapis.com/maps/api/place/search/json?    location=52.247983,-7.141113&radius='+radius+'&types='+values+'&name=&sensor=false&key=AIzaSyAAStZvDJ_5ENODEdSCanLWgJBG6p6eXBQ',
        reader:{
        type:'json',
        rootProperty:'results'
    }
}
});
之后,您可以将tap事件中的url设置为

onSearchTap: function() {

    Ext.Viewport.setActiveItem(Ext.create('FirstApp.view.Main'));

    var values = this.getVisit().getValue();
     var radius = this.getRadius().getValue() * 1000;

    console.log(values);
    console.log(radius);    

   var geo = new Ext.util.Geolocation({
    autoUpdate: false,
    allowHighAccuracy: true,
    listeners: {
    locationupdate: function(geo) {
       lat = geo.getLatitude();
       lon = geo.getLongitude();
       Ext.StoreMgr.get('Places').getProxy().setUrl('https://maps.googleapis.com/maps/api/place/search/json?location='+lat+','+lon+'&radius='+radius+'&types='+values+'&name=&sensor=false&key='');
       Ext.StoreMgr.get('Places').load();    
    }
    }
   });

  geo.updateLocation();
  }

你好,Mayur,我已经尝试了上面的方法,但是我得到了一个未捕获的错误TypeError:无法调用undefined的方法“setUrl”。如果你知道我哪里出错了,那是因为第一次没有创建代理,试着在地理位置编码上方创建代理,然后将其托管到sencha fiddle中。嘿,Mayur,我已经用你的代码更新了原始答案中的代码,并包含了两个js。我发布了新代码,如果这也不工作,然后主机上的sencha小提琴你的应用程序,让我知道