Google map api v3
Ребят, проблема такая:
Все работает, маршрут прокладывается, местоположение определяется, но вместо того чтобы карта двигалась относительно моей геолокации, она начинает заново создаваться, а старая не удаляется и грузит память!!! Координаты конечно верные и все супер, но вот момент между созданием пустой и смотрится ужасно! Как мне сделать так, чтобы карта двигалась, а не создавалась каждый раз новая??? var boolTripTrack = true; var currentLatitude; var currentLongitude; var directionDisplay; var directionsService = new google.maps.DirectionsService(); var map; directionsDisplay = new google.maps.DirectionsRenderer(); function initialize() { var karta = new google.maps.LatLng(currentLatitude, currentLongitude); var myOptions = { zoom: 17, mapTypeId: google.maps.MapTypeId.ROADMAP, center: karta } map = new google.maps.Map(document.getElementById("map_canvas"), options); var marker = new google.maps.Marker({ position: karta, map: map, icon: 'me.png' }); calcRoute(); directionsDisplay.setMap(map); directionsDisplay.setPanel(document.getElementById("directionsPanel")); google.maps.event.addListener(directionsDisplay, 'directions_changed', function() { computeTotalDistance(directionsDisplay.directions); }); } function calcRoute() { var start = currentLatitude+','+currentLongitude; var end = '54.626803,39.7163787'; var request = { origin:start, destination:end, travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); } var options = { zoom: 17, timeout: 10000, maximumAge: 6000, enableHighAccuracy: true }; //Success callback var suc = function(p) { console.log("geolocation success", 4); //Draws the map initially if(currentLatitude != p.coords.latitude){ currentLatitude = p.coords.latitude; initialize(); } if(currentLongitude != p.coords.longitude){ currentLongitude = p.coords.longitude; initialize(); } }; var fail = function() { console.log("Geolocation failed. \nPlease enable GPS in Settings.", 1); }; var getLocation = function() { console.log("in getLocation", 4); }; //Execute when the DOM loads //The Intel XDK intel.xdk.device.ready event fires once the Intel XDK has fully loaded. //After the device has fired, you can safely make calls to Intel XDK function. function onDeviceReady() { try { if (intel.xdk.device.platform.indexOf("Android") != -1) { intel.xdk.display.useViewport(480, 480); document.getElementById("map_canvas").style.width = "480px"; } else if (intel.xdk.device.platform.indexOf("iOS") != -1) { if (intel.xdk.device.model.indexOf("iPhone") != -1 || intel.xdk.device.model.indexOf("iPod") != -1) { intel.xdk.display.useViewport(320, 320); document.getElementById("map_canvas").style.width = "320px"; } else if (intel.xdk.device.model.indexOf("iPad") != -1) { intel.xdk.display.useViewport(768, 768); document.getElementById("map_canvas").style.width = "768px"; } } if (intel.xdk.iswin8) { document.getElementById("map_canvas").style.width = screen.width + "px"; document.getElementById("map_canvas").style.height = screen.height + "px"; } if (intel.xdk.geolocation !== null) { document.getElementById("map_canvas").style.height = screen.height + "px"; intel.xdk.geolocation.watchPosition(suc, fail, options); } } catch (e) { alert(e.message); } try { //lock orientation intel.xdk.device.setRotateOrientation("portrait"); intel.xdk.device.setAutoRotate(false); } catch (e) {} try { //manage power intel.xdk.device.managePower(true, false); } catch (e) {} try { //hide splash screen intel.xdk.device.hideSplashScreen(); } catch (e) {} } document.addEventListener("intel.xdk.device.ready", onDeviceReady, false); |
Часовой пояс GMT +3, время: 20:58. |