如何在 map 中包含路线?
我正在开发 ionic 框架,这是我的 js,它引用 ionic.html 文件(索引 html 仅包含脚本和 ionic View 的位置)。我已经安装了 map 和地理定位 cordova 插件。
app.controller('MapController', function($scope, $ionicLoading) {
// var myLatlng = new google.maps.LatLng(37.3000, -120.4833);
var mapOptions = {
//center: myLatlng,
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
navigator.geolocation.getCurrentPosition(function(pos) {
map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
var myLocation = new google.maps.Marker({
position: new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude),
map: map,
title: "My Location"
});
// var newLatlng = new google.maps.LatLng(37.3000, -120.4833);
var torriLocation = new google.maps.Marker({
position: new google.maps.LatLng(44.823889, 10.335894000000053),
map: map,
title: "My Location"
});
});
$scope.map = map;
});
对于路线,我的意思是“我如何通过汽车、步行或公共(public)汽车到达特定位置?”
最佳答案
如果你想知道你的运动方向,那么你需要及时检查你的位置(在一段时间或位置改变之后)。因此,请使用 GetCurrentPostion 与 SetIntervale 或 WatchPosition 方法。我们喜欢的代码
setInterval( function(){
navigator.geolocation.getCurrentPosition(success_loc, error_loc, opti)
},(1000 * 60 * 1));
或navigator.geolocation.watchPosition(showPosition);
引用 https://developers.google.com/maps/documentation/javascript/examples/map-geolocation
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition
关于javascript - 在 Ionic Framework Google map 中获取路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41162514/