javascript - 在 Ionic Framework Google map 中获取路线

标签 javascript android cordova dictionary ionic-framework

如何在 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/

相关文章:

java - 在 Java 中使用时间对 ArrayList 进行排序

ios - 是否可以使用 Phonegap 将 PlayN 游戏带到 iOS 上?

javascript - Cordova Statusbar 插件差距

javascript - 绝对定位的 img,jquery 对点击事件没有反应

javascript - appendHtml() 不会附加完整的 HTML - Dart

javascript - 有没有办法更新 HTML 中定义的现有数组?

android - 如何在 Play 商店上传拆分应用程序二进制文件

javascript - 如何为 Google Charts 的 TermCloud 图表提供自定义颜色?

javascript - 仅当按下键盘时 Canvas 才绘制矩形

android - phonegap 地理定位不起作用