简体   繁体   English

在cordova-plugin-googlemaps中获取离子位置

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

I am trying to use cordova-plugin-googlemaps in my ionic 1 project. 我正在尝试在ionic 1项目中使用cordova-plugin-googlemaps The problem is I can not get device location. 问题是我无法获取设备位置。 I am using the method provided by the plugin getMyLocation() 我正在使用插件getMyLocation()提供的方法

Here is my app.js code: 这是我的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();
      });
      });

  });
})

and this th body code in index.html: 这是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>

All I get is a map, no markers pinned to my location 我得到的只是一张地图,没有任何标记固定在我的位置

Can anyone see where the problem is? 谁能看到问题所在?

The best option will be to use Cordova geolocation plugin. 最好的选择是使用Cordova地理位置插件。 It will make your life a lot easier. 这将使您的生活更加轻松。 else check this answer out How to get Client location using Google Maps API v3? 否则,请查看此答案。 如何使用Google Maps API v3获取客户位置?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM