我想將gmap導航等功能添加到離子混合應用程序中,如藍點指針。以前我使用過地理定位API,但是當我改變我的位置時(我似乎是靜態的),位置沒有改變。我想添加像谷歌地圖一樣的實時位置跟蹤。任何人都可以建議我正確的方式?如何在離子應用程序中添加實時位置跟蹤
回答
使用watchPosition和更改地圖上的標記。例如:
var myMarker = null;
// get current position
navigator.geolocation.getCurrentPosition(showPosition);
// show current position on map
function showPosition(position) {
myMarker = new google.maps.Marker({
position: new google.maps.LatLng(position.coords.latitude, position.coords.longitude),
map: new google.maps.Map(document.getElementById("map")),
icon: 'img/icons/myicon.png'
});
}
// watch user's position
navigator.geolocation.watchPosition(watchSuccess, watchError, watchOptions);
// change marker location everytime position is updated
function watchSuccess(position) {
var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
// set marker position
marker.setPosition(latLng);
}
您還可以使用$ cordovaGeolocation插件。看看插件文檔。
getCurrentPosition回報地理位置
watchPosition每次改變時間返回當前位置的當前位置。因此,使用此功能,您可以每次使用setPosition更改地圖上的標記並將座標傳遞給它。
它給出了很好的結果,但它顯示了每個位置更改後的舊標記,如何僅顯示一個標記(最新位置)。 –
謝謝克里斯蒂亞諾你的建議解決了我的問題。在你的代碼中有一個修正,而不是「marker.setPosition(latLng);」我們需要寫「」myMarker.setPosition(latLng); 「 –
您只需向map
屬性應用本地方法setMyLocationEnabled(true)
即可。
見我的例子:
設元件:HTML元素=的document.getElementById( '映射');
this.map = this.googleMaps.create(element);
this.map.setMyLocationEnabled(true);
這最後一行將激活本地當前位置標記。
- 1. 實時位置跟蹤
- 2. 應用程序在後臺運行時的位置跟蹤
- 3. 如何跟蹤內部symfony2應用程序的用戶位置?
- 4. 如何跟蹤android應用程序用戶的位置
- 5. 在java web應用程序中自動跟蹤用戶位置
- 6. 如何跟蹤我的應用程序鎖定的位置
- 7. android - 在應用程序位置跟蹤中的firebase
- 8. 應用程序關閉時跟蹤當前位置
- 9. 如何在C#中跟蹤應用程序的打開實例
- 10. 如何在離子應用程序中添加進度條
- 11. 如何在離子應用程序中添加Admob?
- 12. 如何將跟蹤添加到Java服務器應用程序
- 13. 如何創建一個Android GPS實時跟蹤應用程序?
- 14. 如何在跟蹤應用程序中關閉用戶的位置服務實時檢查
- 15. 如何在我的android應用程序中使用Firebase實時數據庫來跟蹤某個人的位置?
- 16. 在Windows 10中應用程序在後臺時的位置跟蹤?
- 17. 實時跟蹤多個iPhone GPS位置
- 18. 跟蹤電子應用程序卸載
- 19. 跟蹤GPS應用程序 - Android電子
- 20. http跟蹤實用程序
- 21. 用戶郵件跟蹤位置(在閱讀郵件時跟蹤用戶位置)
- 22. 如何在Extjs單頁面應用程序中添加Google Analytics事件跟蹤?
- 23. 如何跟蹤應用程序安裝?
- 24. 在android中跟蹤位置
- 25. 一旦應用程序關閉,跟蹤用戶的位置?
- 26. 跟蹤iPhone應用程序的所有用戶位置算法
- 27. 排序後跟蹤位置
- 28. Windows手機位置跟蹤程序
- 29. 實時/生產Web應用程序中的錯誤跟蹤
- 30. 在java應用程序中跟蹤IO?
https://www.pubnub.com/blog/2017-02-02-realtime-google-maps-tracking-and-live-geolocation-with-javascript/ – Edison
謝謝愛迪生,但我有一個問題,它真的可能只有通過使用谷歌API?如果我不想使用額外的依賴關係,那麼實現該目標的方法是什麼? –
來自Google Maps API的'watchPosition()'功能。它會返回您需要更改地圖中標記的所有信息。 – Cristiano