I was looking for how to display the current location and destination. To achieve this, here is what I did:
Note * replace: YOUR_DESTINATION_ADDRESS with an address in the format: "147 + Wyndham + Street + N +, + Suite + 206, + Guelph, + On, + N1H + 4E9"
<div id="Map" style="width: 100%; height: 600px;"> </div> <script type="text/javascript"> $(function(){ var zoom = 11; function success(position) { var LAT = position.coords.latitude; var LONG = position.coords.longitude; $('#Map').append('<p>Current Latitude: ' + LAT + '<br/>Current Logitude: ' + LONG +'<br/><br/>Note* This may not display your exact location, but just your city. Works better on mobile devices</p>'); var map = '<iframe style="width: 100%; height: 600px;" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.ca/maps?source=s_d&saddr=' + LAT +',+' + LONG +'&daddr=**YOUR_DESTINATION_ADDRESS**&ie=UTF8&t=hz=' + zoom + '&output=embed"></iframe>'; $('#Map').append(map); } function error(){ } function MakeMap(){ if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(success, error); } } MakeMap(); }); </script>
source share