嗨朋友我是新的Sencha Touch平臺。如何在Sencha-Touch2.0的地圖上獲取當前位置的標記
我想找到用戶current location
與請幫我。我陷入這種狀況。
是否有新的好的教程,我那麼請提前爲你的時間與我分享..
感謝。
嗨朋友我是新的Sencha Touch平臺。如何在Sencha-Touch2.0的地圖上獲取當前位置的標記
我想找到用戶current location
與請幫我。我陷入這種狀況。
是否有新的好的教程,我那麼請提前爲你的時間與我分享..
感謝。
不錯的問題。我以前遇到類似的問題。但是,後來我找到了解決辦法。
以下是您可以如何解決它的方法。
演示與的PhoneGap的地理位置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');
}
然後使用的緯度和經度的值,以地圖的中心設置爲它以及設置標記的該值的位置。
...
...
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的simillar應用程序工作2.3.1
使用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。
感謝您的時間,我試過以上代碼。但是,它沒有奏效。我想在Sencha touch2.0中實現...如果上面的代碼工作,那麼你能告訴我如何實現它嗎? – 2012-04-27 06:00:03
你在哪裏遇到問題?哪部分代碼? – 2012-04-27 06:21:23
上面的代碼,我想興奮地添加..,你可以請高清結構明智..... – 2012-04-30 11:48:48