如何在Sencha-Touch2.0中的地图上的当前位置获取标记 [英] How Can I Get marker on current location in map in Sencha-Touch2.0

查看:92
本文介绍了如何在Sencha-Touch2.0中的地图上的当前位置获取标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们新功能 Sencha Touch 平台。

Hey friends i m new to Sencha Touch platform.

我想找到当前位置标记的用户请帮助我。我陷入这种状况。

And I want to find user current location with marker please help me out. i stuck in this condition.

是否有任何新的好的教程,然后请与我分享..

Is there any new good tutorial for me then please share with me..

感谢您提前时间。

Ravi Patel

推荐答案

尼斯的问题。我以前面临过类似的问题。但是,以后,我想出了解决方案。

Nice question. I faced a similar problem before. But, later, I figured out the solution.

以下是您可以解决的问题。

Here's how you can solve it.

  • Either use Phonegap's Geolocation API or ..
  • Use Ext.util.Geolocation from Sencha Touch API

演示与 PhoneGap的Geolocation API


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

  1. Get the geolocation via the 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');
}


  • 然后使用lat和lng的值设置地图的中心对此,以及将标记的位置设置为该值。

  • Then use the values of lat and lng to set the map's center to it as well as set the marker's position to that value.

     ... 
     ...
     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
     });
     ...
     ...
    


  • 这篇关于如何在Sencha-Touch2.0中的地图上的当前位置获取标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆