如何在Sencha-Touch2.0中获取地图中当前位置的标记

Rav*_*tel 6 javascript extjs sencha-touch sencha-touch-2

嘿朋友我是Sencha Touch平台的新手.

我想找到用户current location,marker请帮帮我.我陷入了这种状况.

有没有新的好教程,请与我分享..

在此先感谢您的时间.

拉维帕特尔

sgo*_*les 4

好问题。我以前遇到过类似的问题。但后来我想出了解决办法。

以下是解决该问题的方法。

使用Phonegap 的地理定位 API进行演示

  1. 通过 geolocation api 获取地理位置。

    vat lat, lng;
    var geoLocationOptions = { maximumAge: 3000, timeout: 5000, enableHighAccuracy: true };
    navigator.geolocation.getCurrentPosition(geoLocationSuccess,geoLocationError,geoLocationOptions);
    
    function geoLocationSuccess(position) {
        lat = position.coords.latitude;
        lng = position.coords.longitude;
        Ext.Msg.alert("Geolocation","Latitude:"+ lat +", Longitude:"+ lng); 
    }
    
    function geoLocationError() {
       Ext.Msg.alert('Error','Error while getting geolocation');
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 然后使用 lat 和 lng 的值将地图的中心设置为该值,并将标记的位置设置为该值。

     ... 
     ...
     var position = new google.maps.LatLng(lat,lng);
     map = this.add({
            xtype: 'map',
            getLocation: true,
            autoLoad: true,
            mapOptions: {
                zoom: 15,
                center: position,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                navigationControl: true,
                zoomControl: true,
                mapTypeControl: true,
                scrollwheel: true,
                scaleControl: true,
                zoomControlOptions: {
                    style: google.maps.ZoomControlStyle.LARGE
                }
            }
        });
    
     marker = new google.maps.Marker({
            id: 'geoLocMarker',
            position: position,
            map: map.getMap(),
            visible: true
     });
     ...
     ...
    
    Run Code Online (Sandbox Code Playgroud)