javascript - Google Direction | same API, different result -
i have simple route made on javascript on following link:
http://debug.iott.co.il/map/route.v.1.0.html
edit here image javascript lazy ones.
it's goes b, b c , c d. watch this, when user hit point c need u-turn point d, fine me.
i have tried duplicate same thing on android studio, , i'm getting different route following image:
so instead of doing u-turn c d, it's makes user goto way again, b , lastly d. i'm trying figure out why i'm using same api (google direction) same configuration (driving mode etc.) , i'm getting different results. ideas ?
edit 2: here of code: javascript :
//you can calculate directions (using variety of methods of transportation) using directionsservice object. var directionsservice = new google.maps.directionsservice(); //define variable map points. var _mappoints = new array(); //define directionsrenderer variable. var _directionsrenderer = ''; //this give map zoom value. var zoom_option = 6; //legpoints route points between 2 locations. var legpoints = new array(); var currentpoi = 0; //google map object var map; var route = { 'id': '768cbe75-cade-4498-95c5-7369e8ac9d20', 'name': 'by route 1', 'points': [{ 'latitude': 32.33197427500548, 'longtitude': 34.894479140639305, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': '' }, { 'latitude': 32.330265, 'longtitude': 34.893424, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'l' }, { 'latitude': 32.329581, 'longtitude': 34.894216, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'u' }, { 'latitude': 32.330517, 'longtitude': 34.892191, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'l' }, { 'latitude': 32.329863, 'longtitude': 34.890681, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'r' }, { 'latitude': 32.333253, 'longtitude': 34.890102, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'r' }, { 'latitude': 32.333216, 'longtitude': 34.892721, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'l' }, { 'latitude': 32.337219, 'longtitude': 34.893506, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'r' }, { 'latitude': 32.337473, 'longtitude': 34.893954, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'l' }, { 'latitude': 32.337336, 'longtitude': 34.893433, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'l' }, { 'latitude': 32.337335, 'longtitude': 34.894009, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'r' }, { 'latitude': 32.337281, 'longtitude': 34.894530, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'r' }, { 'latitude': 32.335042, 'longtitude': 34.894198, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'l' }, { 'latitude': 32.335056, 'longtitude': 34.894756, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'r' }, { 'latitude': 32.332629, 'longtitude': 34.894617, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'r' }, { 'latitude': 32.333123, 'longtitude': 34.893378, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'r' }, { 'latitude': 32.335002, 'longtitude': 34.894187, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'r' }, { 'latitude': 32.335120, 'longtitude': 34.895929, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'r' }, { 'latitude': 32.331783, 'longtitude': 34.895945, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'r' }, { 'latitude': 32.332448, 'longtitude': 34.894796, 'direction': 0, 'timestamp': '\/date(1465923981572+0300)\/', 'icon': 'l' }] }; //initializemap() function used initialize google map on page load. function initializemap() { //directionsrenderer() used render direction _directionsrenderer = new google.maps.directionsrenderer({ draggable: true, map: map, panel: document.getelementbyid('right-panel') }); //set own options map. var myoptions = { zoom: zoom_option, zoomcontrol: true, center: new google.maps.latlng(32.2679, 34.3718), maptypeid: google.maps.maptypeid.roadmap }; //define map. map = new google.maps.map(document.getelementbyid("dvmap"), myoptions); //set map directionsrenderer _directionsrenderer.setmap(map); //set different options directionsrenderer mehtods. //draggable option used drag route. _directionsrenderer.setoptions({ draggable: false }); ////add doubel click event map. //google.maps.event.addlistener(map, "dblclick", function (event) { // var _currentpoints = event.latlng; // _mappoints.push(_currentpoints); // legpoints.push(''); // getroutepointsandwaypoints(_mappoints); //}); //add directions changed event map. google.maps.event.addlistener(_directionsrenderer, 'directions_changed', function() { var myroute = _directionsrenderer.directions.routes[0]; createroute(myroute); zoom_option = map.getzoom(); }); initialroute(); } function initialroute() { var latlon = new google.maps.latlng(); (var = currentpoi; < route.points.length && < currentpoi+10; i++) { latlon = new google.maps.latlng(route.points[i].latitude, route.points[i].longtitude); _mappoints.push(latlon); legpoints.push(latlon); window.settimeout(function () { getroutepointsandwaypoints(_mappoints); }, 100); } currentpoi += 10; if (currentpoi > route.points.length) { currentpoi = 0; } } function computetotaldistance(result) { var total = 0; var myroute = result.routes[0]; (var = 0; < myroute.legs.length; i++) { total += myroute.legs[i].distance.value; } total = total / 1000; document.getelementbyid('total').innerhtml = total + ' km'; } function createroute(myroute) { var index = 0; if (_mappoints.length > 10) { index = _mappoints.length - 10; } (var = 0; < myroute.legs.length; i++) { savelegpoints(myroute.legs[i], index); index = index + 1; } } //saving legs points between 2 routes function savelegpoints(leg, index) { var points = new array(); (var = 0; < leg.steps.length; i++) { (var j = 0; j < leg.steps[i].lat_lngs.length; j++) { points.push(leg.steps[i].lat_lngs[j]); } } legpoints[index] = points; } //this draw more 10 points route on map. function drawpreviousroute(legs) { var segpointvalue = new array(); (var = 0; < legs; i++) { var innerarry = legpoints[i]; (var j = 0; j < innerarry.length; j++) { segpointvalue.push(innerarry[j]); } addpreviousmarker(innerarry[0],i); } var polyoptions = { path: segpointvalue, strokecolor: '#ffcc00', strokeweight: 5 }; var poly = new google.maps.polyline(polyoptions); poly.setmap(map); } //this wil add marker icon route. function addpreviousmarker(mylatlng,id) { var pinimage = new google.maps.markerimage("http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=" + id + "|ffcc00|0000ff"); //var pinimage = { // url: "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=" + id + "|ffcc00|0000ff" // //size: new google.maps.size(71, 71), // //origin: new google.maps.point(0, 0), // //anchor: new google.maps.point(17, 34), // //scaledsize: new google.maps.size(25, 25) //}; var marker = new google.maps.marker({ position: mylatlng, icon: pinimage,//"images/red-circle.png", title: "" }); marker.setmap(map); } //getroutepointsandwaypoints() pass points , waypoints drawroute() function function getroutepointsandwaypoints(points) { if (points.length <= 10) { drawroutepointsandwaypoints(points); } else { var newpoints = new array(); var startpoint = points.length - 10; var legs = points.length - 10; (var = startpoint; < points.length; i++) { newpoints.push(points[i]); } drawroutepointsandwaypoints(newpoints); drawpreviousroute(legs); } } function drawroutepointsandwaypoints(points) { //define variable waypoints. var _waypoints = new array(); if (points.length > 2) //waypoints come. { (var j = 1; j < points.length - 1; j++) { var address = points[j]; if (address !== "") { _waypoints.push({ location: address, stopover: true //stopover used show marker on map waypoints }); } } //call drawroute() function drawroute(points[0], points[points.length - 1], _waypoints); } else if (points.length > 1) { //call drawroute() function start , end locations drawroute(points[_mappoints.length - 2], points[points.length - 1], _waypoints); } else { //call drawroute() function 1 point start , end locations. drawroute(points[_mappoints.length - 1], points[points.length - 1], _waypoints); } } //drawroute() actual draw route on map. function drawroute(originaddress, destinationaddress, _waypoints) { //define request variable route . var _request = ''; //this more 2 locatins if (_waypoints.length > 0) { _request = { origin: originaddress, destination: destinationaddress, waypoints: _waypoints, //an array of waypoints optimizewaypoints: false, //set true if want google determine shortest route or false use order specified. travelmode: google.maps.directionstravelmode.driving }; } else { //this 1 or 2 locations. here noway point used. _request = { origin: originaddress, destination: destinationaddress, travelmode: google.maps.directionstravelmode.driving }; } //this take request , draw route , return response , status output directionsservice.route(_request, function(_response, _status) { if (_status == google.maps.directionsstatus.ok) { _directionsrenderer.setdirections(_response); computetotaldistance(_directionsrenderer.getdirections()); } }); }
the code in android simple routing call using library.
routing routing = new routing.builder() .travelmode(routing.travelmode.driving) .withlistener(this) .waypoints(firsteightwaypoints) .language("iw") .build(); routing.execute();
Comments
Post a Comment