【问题标题】:Getting location in cordova-plugin-googlemaps for ionic在cordova-plugin-googlemaps中获取离子的位置
【发布时间】:2017-05-12 00:36:13
【问题描述】:

我正在尝试在我的 ionic 1 项目中使用 cordova-plugin-googlemaps。 问题是我无法获取设备位置。 我使用的是插件getMyLocation()提供的方法

这是我的 app.js 代码:

    angular.module('starter', ['ionic','ngCordova'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
      var div = document.getElementById("map_canvas");
      var map = plugin.google.maps.Map.getMap(div);
      map.getMyLocation(function(location) {
      var msg = ["Current your location:\n",
      "latitude:" + location.latLng.lat,
      "longitude:" + location.latLng.lng,
      "speed:" + location.speed,
      "time:" + location.time,
      "bearing:" + location.bearing].join("\n");
      map.addMarker({
        'position': location.latLng,
        'title': msg
      }, function(marker) {
        marker.showInfoWindow();
      });
      });

  });
})

以及 index.html 中的这个正文代码:

<body ng-app="starter">

<ion-pane>
  <ion-header-bar class="bar-stable">
    <h1 class="title">Ionic Map Project</h1>
  </ion-header-bar>
  <ion-content>
      <div style="width:100%;height:500px;" id="map_canvas"></div>

  </ion-content>
</ion-pane>

我得到的只是一张地图,没有标记我的位置

谁能看出问题出在哪里?

【问题讨论】:

    标签: javascript cordova ionic-framework


    【解决方案1】:

    最好的选择是使用 Cordova 地理定位插件。它会让你的生活轻松很多。否则请查看此答案How to get Client location using Google Maps API v3?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-04
      • 2016-12-20
      • 1970-01-01
      • 2016-11-06
      • 2017-12-21
      相关资源
      最近更新 更多