how to draw a path on google maps by zip code -


I want to show the distance between a pin map and zip code or city name L. The map between them Will be generated, the total distance between them will be calculated, please help with this. Thank you in advance

You can do it in three steps
1) Post city or city zip Create code - map1.php

  & lt; Html & gt; & Lt; Top & gt; & Lt; Meta name = "viewport" content = "initial-scale = 1.0, user-scalable =" /> & Lt; Meta http-equiv = "content-type" content = "text / html; charset = UTF-8" /> & Lt; Title & gt; Google Maps JavaScript API v3 example: Post City or Zip & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form action = "map2.php" method = "post" & gt; 1 zip code / city & lt; Type input = "text" name = "input1" id = "input1" & gt; & Lt; Br / & gt; Second zip code / city & lt; Type input = "text" name = "input2" id = "input2" & gt; & Lt; Input type = "submit" & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;   

2) Create map2.php and create a map -

  & lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Meta name = "viewport" content = "initial-scale = 1.0, user-scalable =" /> & Lt; Meta http-equiv = "content-type" content = "text / html; charset = UTF-8" /> & Lt; Title & gt; Google Maps JavaScript API v3 example: Directions simplified & lt; / Title & gt; & Lt; Link href = "http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel = "stylesheet" type = "text / css" /> & Lt; Script type = "text / javascript" src = "http://maps.googleapis.com/maps/api/js?sensor=false" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; Display different directions; Var Directions service = new google.maps.DirectionsService (); Var map; Start function () {directionsDisplay = new google.maps.DirectionsRenderer (); Var Chicago = new google.maps.LatLng (41.850033, -87.6500523); Var myOptions = {Zoom: 7, Map Type IID: google.maps.MapTypeId.ROADMAP, Center: Chicago) Map = New google.maps.Map (document.getElementById ("map_canvas"), myOptions); DirectionsDisplay.setMap (map); } Function calcRoute () {var start = '& lt ;? Php echo $ _POST ['input1']; ? & Gt; '; Var end = '& lt ;? Php ek $ _POST ['input2']; ? & Gt; '; Var Request = {Origin: Start, Destination: End, Travel Mode: google.maps.DirectationsTravelMode.DRIVING}; DirectionsService.route (request, function (response, status) {if (position == google.maps.DirectionsStatus.OK) {directionsDisplay.setDirections (response);}}); } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body Onload = "Initialize (), Calculate ()" & gt; & Lt ;? Calculate the loglong by php // address and zip code function getLatLong ($ address) {if (! Is_string ($ address) dies) ("All addresses must be passed as string"); $ _url = sprintf ('http://maps.google.com/maps?output=js&q=%s',rawurlencode ($ address)); $ _result = false; If ($ _come = file_gate_content ($ _ url)) (if (strokes ($ _ result, 'error')> gt; 1 || stropo ($ _ result, 'did you mean:')! == incorrect ) Return return; Preg_match ('center: \ s * {lat: \ s * (-? \ D + \. \ D +), LNG: \ s * (-? \ D + \. \ D +)} ! U ', $ _ Pansal, $ _match); $ _core [' latitude '] = $ _m [1]; $ _core [' long '] = $ _m [2];} $ _cored return;} $ To get = = ($ _ POST ['input1']); echo "
"; print_r ($ to); $ to = getLatLong ($ _ POST ['input2']); Echo "
"; print_r (from $); echo distance ($ '[late']], $ [['long']], $ ['lie]] , Calculate distance by $ ['long'], 'm'). "Mile"; // late long function distance ($ lat 1, $ lon1, $ lat2, $ lon2, $ unit) { $ Theta = $ lon1 - $ lon2; $ Dist = sin (deg2rad ($ lat1)) * sin (deg2rad ($ lat2)) + cos (deg2rad ($ lat1)) * cos (deg2rad ($ lat2)) * cos ( Deg2rad ($ theta)); $ dist = acos ($ dist); $ dist = rad2deg ($ dist); $ mile = $ dist * 60 * 1.1515; $ unit = stratupper ($ unit); if ($ unit == "Ki") {return ($ mile * 1.60 9 344); } And if ($ unit == "n") {return ($ mile * 0.8684); } And {return $ mile; }}? & Gt; & Lt; Div id = "map_canvas" style = "top: 30px;" & Gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;

The map and getLatLong () functions are found, the distance between the city or the zip code can be the distance of distance function

Comments