2016-12-19 17 views
1

地図を描画し、正確な緯度を正確に設定したときにのみ正しく動作する現在の場所にカメラをアニメーションするには、次のコードを使用します(正確な数値)。ユーザーの現在地を渡す必要がありますですので、私はこのtutorialでこのCordova google mapsプラグイン

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!"); 

     }); 
    }); 
    }); 
} 

答えて

0

チェックするために、ユーザーの現在位置を渡す方法を知っておく必要があります。 cordova-geolocation-pluginまたはCordova 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 postに記載されているコードに従うこともできます。

関連する問題