javascript - Google Maps Roads API: Making 'snap to road' more forgiving -
i've been tasked using google maps api create tool restaurant can use define delivery zones. here progress: http://codepen.io/keithpickering/pen/nqdzko
users should able draw polygon, after snap nearby roads accuracy. working relatively well, except fact google's built-in snap road functionality...well, sort of sucks. if points aren't close enough together, either refuse snap anything, or make weird janky line.
what need tool more "forgiving" road snapping; in other words, should able lazily draw pretty sort of polygon zoom distance, , lines should forced snap 1 road or another.
here part of code i'm using snap:
... // snap polygon roads placeidarray = []; runsnaptoroad(poly, path, color); }); // snap user-created polyline roads , draw snapped path function runsnaptoroad(poly, path, color) { var pathvalues = []; (var = 0; < path.getlength(); i++) { pathvalues.push(path.getat(i).tourlvalue()); } $.get('https://roads.googleapis.com/v1/snaptoroads', { interpolate: true, key: apikey, path: pathvalues.join('|') }, function(data) { processsnaptoroadresponse(data); drawsnappedpolyline(poly, path, color); }); } // store snapped polyline returned snap-to-road method. function processsnaptoroadresponse(data) { snappedcoordinates = []; placeidarray = []; (var = 0; < data.snappedpoints.length; i++) { var latlng = new google.maps.latlng( data.snappedpoints[i].location.latitude, data.snappedpoints[i].location.longitude); snappedcoordinates.push(latlng); placeidarray.push(data.snappedpoints[i].placeid); } }
will necessary give on roads api , go more customized solution using directions service? have ideas? , help.
unfortunately, cannot done current api. api designed correct paths traversed roads , takes consideration factors permitted traffic directions (i.e. one-way roads), valid turns , ordering of provided points.
a freehand drawing of path near roads may not valid route (especially distant zoom level), api not finding path high probability of being real.
if like, can request feature on issue tracker.
Comments
Post a Comment