Introduction
This article demonstrates the following::
- Google map using JavaScript
- GeoComplete JavaScript for search address
- Custom pin point for Google map
- Travel mode and Route between pickup and drop off address
- Calculate total distance & time to reach your destination
1. Initialize Map
- Here I have created code for map initialization and accessing your location.
- I wrote a method inside a document ready for map initialization.
- The navigator method is asked for a sharing location that returns your current latitude and longitude.
- Using lat and long we can render your current position on the map.
- $(document).ready(function()
- {
- //map initialize
- initialize();
- });
- function initialize()
- {
- //ask for share location
- navigator.geolocation.getCurrentPosition(doStuff, error, setOptions);
- function setOptions(geoLoc)
- {
- geoLoc.enableHighAccuracy = true;
- geoLoc.timeout = 30;
- geoLoc.maximumAge = 0;
- }
- function doStuff(geoLoc)
- {
- latlong = new google.maps.LatLng(geoLoc.coords.latitude, geoLoc.coords.longitude);
- geolatitude = geoLoc.coords.latitude;
- geolongitude = geoLoc.coords.longitude;
- var mapOptions = {
- center: latlong,
- zoom: 15,
- mapTypeId: google.maps.MapTypeId.ROADMAP
- };
- var image = 'img/home_alt.png';
- map = new google.maps.Map(document.getElementById('mapCanvas'), mapOptions);
- marker = new google.maps.Marker(
- {
- position: latlong,
- map: map,
- icon: image
- });
- }
- }
- When you share location your screen looks like the following image:

2. Search your location
- I used geocomplete JS for the search location.
- The following code is for search location and binding your location in textbox and label.
- $(function()
- {
- $("#PickupAddress")
- .geocomplete()
- .bind("geocode:result", function(event, result)
- {
- $("#spanPick").text($("#PickupAddress").val());
- pickUpLatLong = new google.maps.LatLng(result.geometry.location.lat(), result.geometry.location.lng());
- routeDirection("PickupAddress", pickUpLatLong);
- });
- });


Abhishek MishraPosted May 10, 2018, 5:24 AM
Nice one..............
Santhakumar MunuswamyPosted Nov 11, 2015, 8:43 AM
Good one
Kunal PatelPosted Nov 7, 2015, 12:07 AM
Thanks to all
Sibeesh VenuPosted Nov 6, 2015, 12:15 AM
Nice Share
Rajeesh MenothPosted Nov 5, 2015, 11:55 PM
Nice!
Humayun Kabir MamunPosted Nov 5, 2015, 11:33 PM
Nice...
Harshad PansuriyaPosted Nov 5, 2015, 11:30 PM
Nice one