簡體   English   中英

在cordova-plugin-googlemaps中獲取離子位置

[英]Getting location in cordova-plugin-googlemaps for ionic

我正在嘗試在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>

我得到的只是一張地圖,沒有任何標記固定在我的位置

誰能看到問題所在?

最好的選擇是使用Cordova地理位置插件。 這將使您的生活更加輕松。 否則,請查看此答案。 如何使用Google Maps API v3獲取客戶位置?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM