繁体   English   中英

科尔多瓦Google Maps插件

[英]Cordova google maps plugin

我有以下代码来绘制地图并将摄像机动画化到我的当前位置,只有当我输入精确的经纬度(精确数字)时,它才能正常工作,但是无论他在哪里,我都需要传递用户当前位置,所以我需要知道如何将用户当前位置传递给此

var map;
document.addEventListener("deviceready", function() {
  var div = document.getElementById("map_canvas");

  // Initialize the map view 
  map = plugin.google.maps.Map.getMap(div);

  // Wait until the map is ready status. 
  map.addEventListener(plugin.google.maps.event.MAP_READY, onMapReady);
}, false);


function onMapReady() {
  // Move to the position with animation 
  map.animateCamera({
    target: {lat: 30.1234567, lng: 31.1234567},
    zoom: 17,
    tilt: 60,
    bearing: 140,
    duration: 5000
  }, function() {

    // Add a maker 
    map.addMarker({
      position: {lat: 30.1234567, lng: 31.1234567},
      title: "Welecome to \n" +
             "Cordova GoogleMaps plugin for iOS and Android",
      snippet: "This plugin is awesome!",
      animation: plugin.google.maps.Animation.BOUNCE
    }, function(marker) {

      // Show the info window 
      marker.showInfoWindow();

      // Catch the click event 
      marker.on(plugin.google.maps.event.INFO_CLICK, function() {

        // To do something... 
        alert("Hello world!");

      });
    });
  });
}

查看本教程 使用cordova-geolocation-pluginCordova Background Geolocation ,它的工作更加稳定并且功能更多。 您可以将结果传递回地图插件。

var onSuccess = 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();
  });
};

var onError = function(msg) {
  alert("error: " + msg);
};
map.getMyLocation(onSuccess, onError);

您也可以遵循此SO帖子中给出的代码。

暂无
暂无

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

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