[英]How Can I Get marker on current location in map in Sencha-Touch2.0
嘿朋友我是Sencha Touch平台的新手。
我想用marker
找到用户current location
请帮帮我。 我陷入了这种状况。
有没有新的好教程,请与我分享..
在此先感谢您的时间。
好问题。 我之前遇到过类似的问题。 但是,后来,我找到了解决方案。
这是你如何解决它。
使用Phonegap的Geolocation API进行演示
通过地理位置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的值将地图的中心设置为它,并将标记的位置设置为该值。
... ... 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 }); ... ...
如果你只是使用Ext.Map.getGeo(),它会更简单,如下所示:
var geo = extmap.down("#Map").getGeo();
var currentPosition = new google.maps.LatLng(geo.getLatitude(), geo.getLongitude());
只要您实例化了地图,如果浏览器客户端允许您获取该地图,则应获取当前位置。
HTH!
我也使用sencha touch 2.3.1为simillar应用程序工作
使用Ext.util.Geolocation类获取当前位置,并使用以下代码自动更新currentPosition。
Ext.create('Ext.util.Geolocation', {
autoUpdate: true,
allowHighAccuracy: true,
frequency: '5000', // set the milliseconds for the location update
listeners: {
locationupdate: function(geo) {
latitude=Global.currentUserLocations.currentLat;
longitude=Global.currentUserLocations.currentLong;
if(Global.currentUserPositionMarker)
{
latlng1=new google.maps.LatLng(latitude, longitude);
Global.currentUserPositionMarker.setPosition(latlng1);
}
}
}
});
以上代码适用于我,我已经在我的应用程序中使用获取currentLocation并将标记移动到currentPosition。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.