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

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

问题描述

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

Hey friends i m new to Sencha Touch platform.

我想用 marker 查找用户 current location 请帮帮我.我陷入了这种情况.

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..

提前感谢您的时间.

拉维·帕特尔

推荐答案

好问题.我之前也遇到过类似的问题.但是,后来,我想出了解决办法.

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

这是解决问题的方法.

使用 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天全站免登陆