javascript - Custom routes/paths/roads on Google Maps -
hey guys. need know if need achievable.
i need able to, using either v2 or v3 (preferably 3), create paths ignore buildings in sense.
i trying create kml file draw out of paths myself, , find way turn them on/off needed.
for example. user wants go point point b. between these points number of buildings. user physically can walk through these buildings(it's campus). want show them on map.
this way don't have loop-de-loop around, say, parking lot, other end of it.
if there way @ this, i'd love know.
an example of require can found here: http://www.uottawa.ca/maps/
it's pre-determined paths based on 2 inputs user dropdown menu. can plainly see this. have no clue if a) can done in v3, , b) how on earth did themselves.
assistance required, , appreciated!
if campus not big, may want consider defining polyline routes hand each permutation, such if have 4 buildings a, b, c , d, need define 6 routes:
a:b, a:c, a:d, b:c, b:d, c:d
then build basic javascript logic, when chose building starting point , building c destination, hide polylines , show a:c line only. can use google's polyline methods length in meters of each route, if required.
this short table of how many routes have define, according number of buildings have:
+-------------+--------+ | buildings | routes | |-------------+--------+ | 5 | 10 | | 10 | 45 | | 15 | 105 | | 20 | 190 | | 25 | 300 | +-------------+--------+
as can see, gets out of control number of buildings goes up, option feasible point. @ least lucky since order of permutations not important, assuming people can walk each route in both directions.
interesting note: noticed ottawa demo supplied not making ajax calls when requesting directions. therefore there chance doing same suggested above.
update:
here working demo using v3 maps api, hope can getting started:
<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>google maps campus</title> <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> </head> <body> <div id="map" style="width: 550px; height: 400px"></div> <div>start: <select id="start"> <option>building 1</option> <option>building 2</option> <option>building 3</option> </select> </div> <div>end: <select id="end"> <option>building 1</option> <option>building 2</option> <option>building 3</option> </select> </div> <input type="button" onclick="drawdirections();" value="go" /> <script type="text/javascript"> var mapoptions = { maptypeid: google.maps.maptypeid.terrain, center: new google.maps.latlng(47.690, -122.310), zoom: 12 }; var map = new google.maps.map(document.getelementbyid("map"), mapoptions); // predefine paths var paths = []; paths['1_to_2'] = new google.maps.polyline({ path: [ new google.maps.latlng(47.656, -122.360), new google.maps.latlng(47.656, -122.343), new google.maps.latlng(47.690, -122.310) ], strokecolor: '#ff0000' }); paths['1_to_3'] = new google.maps.polyline({ path: [ new google.maps.latlng(47.656, -122.360), new google.maps.latlng(47.656, -122.343), new google.maps.latlng(47.690, -122.270) ], strokecolor: '#ff0000' }); paths['2_to_3'] = new google.maps.polyline({ path: [ new google.maps.latlng(47.690, -122.310), new google.maps.latlng(47.690, -122.270) ], strokecolor: '#ff0000' }); function drawdirections() { var start = 1 + document.getelementbyid('start').selectedindex; var end = 1 + document.getelementbyid('end').selectedindex; var i; if (start === end) { alert('please choose different buildings'); } else { // hide polylines (i in paths) { paths[i].setoptions({ map: null }); } // show route if (typeof paths['' + start + '_to_' + end] !== 'undefined') { paths['' + start + '_to_' + end].setoptions({ map: map }); } else if (typeof paths['' + end + '_to_' + start] !== 'undefined') { paths['' + end + '_to_' + start].setoptions({ map: map }); } } } </script> </body> </html>
screenshot:
Comments
Post a Comment