javascript - Add milestones (markers) every x Km on direction -
i want add marker every 5 or 10 kilometer on polylines of direction given google maps api. :
http://www.geocodezip.com/v3_polyline_example_kmmarkers_0.html
but google direction's
given start point, initial bearing, , distance, calculate destination point , final bearing travelling along (shortest distance) great circle arc.
var lat2 = math.asin( math.sin(lat1)*math.cos(d/r) + math.cos(lat1)*math.sin(d/r)*math.cos(brng) ); var lon2 = lon1 + math.atan2(math.sin(brng)*math.sin(d/r)*math.cos(lat1), math.cos(d/r)-math.sin(lat1)*math.sin(lat2));
the radius of earth (r
) 6371000 meters. brng
direction travelling in degrees (0 = north).
then use function add markers map
function setmarkers(map, locations) { // add markers map // marker sizes expressed size of x,y // origin of image (0,0) located // in top left of image. // origins, anchor positions , coordinates of marker // increase in x direction right , in // y direction down. var image = { url: 'images/beachflag.png', // marker 20 pixels wide 32 pixels tall. size: new google.maps.size(20, 32), // origin image 0,0. origin: new google.maps.point(0,0), // anchor image base of flagpole @ 0,32. anchor: new google.maps.point(0, 32) }; var shadow = { url: 'images/beachflag_shadow.png', // shadow image larger in horizontal dimension // while position , offset same main image. size: new google.maps.size(37, 32), origin: new google.maps.point(0,0), anchor: new google.maps.point(0, 32) }; // shapes define clickable region of icon. // type defines html <area> element 'poly' // traces out polygon series of x,y points. final // coordinate closes poly connecting first // coordinate. var shape = { coord: [1, 1, 1, 20, 18, 20, 18 , 1], type: 'poly' }; (var = 0; < locations.length; i++) { var beach = locations[i]; var mylatlng = new google.maps.latlng(beach[1], beach[2]); var marker = new google.maps.marker({ position: mylatlng, map: map, shadow: shadow, icon: image, shape: shape, title: beach[0], zindex: beach[3] }); } }
edit function have proper marker icons , call each marker want place.
Comments
Post a Comment