Google maps is a free web mapping service application provided by Google. It offers lots of cool features (showing various map types, plotting points, showing routes, geocoding addresses). You can also add all these features to your website using the Google Maps APIs provided by Google. In this tutorial I will show you how to add some of these features to your site. I will be using the Google Maps Javascript API v3 (the newest version).


Table of Contents:

  1. Creating the web form for getting the two addresses
  2. Showing the map
  3. What are we going to add?
  4. Adding custom markers
  5. Making the markers draggable
  6. Choosing the travel mode
  7. Saving the selected map setting

We Are Going to Build a Distance Finder With Google API

We’ll make a distance finder. We’ll add a Google map to our site, plot two points on it (the user will be able to choose the addresses for these points), compute the distance between them and show the quickest route between them.

Also, you can download the source code using this link.

Prerequisites

The first thing you need to do in order to use the API from Google is requesting an API key. You can do this here. It’s easy and free!


Creating the web form for getting the two addresses

We’ll create a simple html form for the user to write the two addresses. We’ll add two input boxes and a button to the form. When the user presses the “Show” button, the map with the two locations will be shown.


Here’s the code for this:

[html]

<table align="center" valign="center">

<tr>

<td colspan="7" align="center"><b>Find the distance between two locations</b></td>

</tr>

<tr>
&nbsp;
</tr>

<tr>

<td>First address:</td>

&nbsp;
<input name="<span class=" type="text" />address1" id="address1" size="50"/>
&nbsp;

<td>Second address:</td>

&nbsp;
<input name="<span class=" type="text" />address2" id="address2" size="50"/>
</tr>

<tr>
&nbsp;
</tr>

<tr>

<td colspan="7" align="center"><input type="button" value="Show" onclick="initialize();"/></td>

</tr>

</table>

[/html]

The ‘initialize’ JavaScript function will be called when pressing the button. The function will show the map. In the next section I’ll show you how.

We also need to add a div tag to our page, where the map will be shown:

[html]

<div id="map_canvas" style="width:70%; height:54%"></div>

[/html]

We will also need two div tags for showing the distances we will compute:

[html]

<div style="width:100%; height:10%" id="distance_direct"></div>

<div style="width:100%; height:10%" id="distance_road"></div>

[/html]


Showing the map

The first thing we need to do is to find the coordinates (latitude and longitude) for the two addresses. Luckily, Google Maps will help us! Here’s what we have to do:


We’ll use the geocoder object for this. First, we’ll have to create a new geocoder object.

[js]geocoder = new google.maps.Geocoder();[/js]

After this, we’ll get the two address values from the form. Like this:

[js]address1 = document.getElementById("address1").value;
address2 = document.getElementById("address2").value;[/js]

Then, we’ll use the following code to call the geocode method on the geocoder object. We’ll pass it the addresses one by one and save the results in the variables called location1 and location2 (these will hold the coordinates of the two addresses).

[js]if (geocoder)
{
geocoder.geocode( { ‘address’: address1}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
//location of first address (latitude + longitude)
location1 = results[0].geometry.location;
} else
{
alert("Geocode was not successful for the following reason: " + status);
}
});
geocoder.geocode( { ‘address’: address2}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
//location of second address (latitude + longitude)
location2 = results[0].geometry.location;
// calling the showMap() function to create and show the map
showMap();
} else
{
alert("Geocode was not successful for the following reason: " + status);
}
});
}[/js]

You will notice that we’ve called the showMap() function when the coordinates for the second address are retrieved. This function will set the options for the map and show it.

We’ll now compute the coordinates for the center of the map. The center point will be between our two points.

[js]latlng = new google.maps.LatLng((location1.lat()+location2.lat())/2,(location1.lng()+location2.lng())/2);[/js]

Next, we’ll show the map. We have to create a new map object and pass it some parameters (set using the mapOptions variable): the zoom level, the center and the type of the map.

[js]var mapOptions =
{
zoom: 1,
center: latlng,
mapTypeId: google.maps.MapTypeId.HYBRID
};

map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);[/js]

The next thing we’ll do is to show the quickest route between our locations. We’ll use a DirectionsService object from google maps for this. Here’s how the code looks:

[js]directionsService = new google.maps.DirectionsService();
directionsDisplay = new google.maps.DirectionsRenderer(
{
suppressMarkers: true,
suppressInfoWindows: true
});
directionsDisplay.setMap(map);
var request = {
origin:location1,
destination:location2,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status)
{
if (status == google.maps.DirectionsStatus.OK)
{
directionsDisplay.setDirections(response);
distance = "The distance between the two points on the chosen route is: "+response.routes[0].legs[0].distance.text;
distance += "The aproximative driving time is: "+response.routes[0].legs[0].duration.text;
document.getElementById("distance_road").innerHTML = distance;
}
});[/js]

We’ve first created the objects we need. We then set some options for displaying the route, we’ve chosen not to show markers and info boxes (we’ll create our own ones);

[js]suppressMarkers: true,
suppressInfoWindows: true[/js]

We’ve created a request object and set the origin and destination for the route and also the travel mode:

[js]var request = {
origin:location1,
destination:location2,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};[/js]

We’ve then called the route function and obtained a response from the server. Using this response we’ve plotted the route on the map and written some info (the total distance and aproximative driving time) in one of the divs we’ve created:

[js]directionsDisplay.setDirections(response);
distance = "The distance between the two points on the chosen route is: "+response.routes[0].legs[0].distance.text;
distance += "The aproximative driving time is: "+response.routes[0].legs[0].duration.text;
document.getElementById("distance_road").innerHTML = distance;[/js]

We’ll also show a line between our points and compute the distance between them (the distance on a straight line, in kilometers). To show a line we’ll use a Polyline object from google maps and set some options for it (the map it belongs to, the path, the width, the opacity and the color):

[js]var line = new google.maps.Polyline({
map: map,
path: [location1, location2],
strokeWeight: 7,
strokeOpacity: 0.8,
strokeColor: "#FFAA00"
});[/js]

We’ll now compute the distance between two points using their coordinates and show the result inside the other div tag we’ve created.

[js]var R = 6371;
var dLat = toRad(location2.lat()-location1.lat());
var dLon = toRad(location2.lng()-location1.lng());
var dLat1 = toRad(location1.lat());
var dLat2 = toRad(location2.lat());
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(dLat1) * Math.cos(dLat1) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;

document.getElementById("distance_direct").innerHTML = "The distance between the two points (in a straight line) is: "+d;[/js]

The last thing we’ll do is show a marker and an info window for each location. We’ll create two marker objects (the options we’ll set are: the map it belongs to, the coordinates and a title):

[js]var marker1 = new google.maps.Marker({
map: map,
position: location1,
title: "First location"
});

var marker2 = new google.maps.Marker({
map: map,
position: location2,
title: "Second location"
});[/js]

Next, we’ll create variables to hold the texts to print in the info windows, create two info window objects (we’ll add the texts to them using the content option) and we’ll add two event listeners which will show the appropriate info window when the user clicks on the markers:

[js]// create the text to be shown in the infowindows

var text1 = ‘

<div id="content">’+</div>

<h1 id="firstHeading">First location’+

<div id="bodyContent">’+

Coordinates: ‘+location1+’

‘+

Address: ‘+address1+’

‘+
‘</div>

‘+
‘</div>

‘;

var text2 = ‘

<div id="content">’+</div>

<h1 id="firstHeading">Second location’+

<div id="bodyContent">’+

Coordinates: ‘+location2+’

‘+

Address: ‘+address2+’

‘+
‘</div>

‘+
‘</div>

‘;

// create info boxes for the two markers
var infowindow1 = new google.maps.InfoWindow({
content: text1
});
var infowindow2 = new google.maps.InfoWindow({
content: text2
});

// add action events so the info windows will be shown when the marker is clicked
google.maps.event.addListener(marker1, ‘click’, function() {
infowindow1.open(map,marker1);
});

google.maps.event.addListener(marker2, ‘click’, function() {
infowindow2.open(map,marker2);
});[/js]

And we’re done! We now have a distance calculator! Let me know if you have any questions! For more advanced users, we are going to add some more stuff. Read on!


What are we going to add?

We’re going to add custom markers to our map and a new feature: draggable markers. The user will be able to drag the markers around the map and the route will be computed again. We will also let the user choose what type of route to show on the map (the available options are driving, walking and bicycling). Another thing we’ll add is saving the map type selected by the user. This way, the selection will be saved when the user presses the “show” button next time and the user won’t have to select the desired map type each time he refreshes the map.


Prerequisites

Apart from adding the new features, I’ve made a small change to the programs structure: I’ve made a separate function for showing the route between the two points (called drawRoutes()). I’ve done this because we’ll have to call this function each time one of the markers is dragged by the user.


Adding custom markers

The first thing we’ll add are custom markers. For this, we need a small image, I’ve used a silly one as an example. The code to set the image as the marker looks like this:


[js]
var rabbit = new google.maps.MarkerImage(‘distance-finder-custom-marker-image.png’);
// create the markers for the two locations
var marker1 = new google.maps.Marker({
map: map,
position: location1,
title: "First location",
icon: rabbit,
draggable: true
});
var marker2 = new google.maps.Marker({
map: map,
position: location2,
title: "Second location",
icon: rabbit,
draggable: true
});
[/js]

We’ve defined a new MarkerImage object and given it the location of the image for the marker. Also, we’ve changed the options a bit when creating the markers: we’ve added the icon parameter.


Making the markers draggable

As you can see from the previous piece of code, we’ve also set the “draggable” parameter to true, making our markers draggable. The user can now drag the markers anywhere on the map. But nothing happens when the markers are dragged! We’ll have to add the code to find the address of the new locations and show the new route. But first, we’ll have to add another action listener to the markers, to define the function to be called when the user stops dragging the marker.


Here’s what we have to add to our code:

[js]
// add action events for dragging the markers
google.maps.event.addListener(marker1, ‘dragend’, function() {
location1 = marker1.getPosition();
drawRoutes(location1, location2);
});
google.maps.event.addListener(marker2, ‘dragend’, function() {
location2 = marker2.getPosition();
drawRoutes(location1, location2);
});
[/js]

We’ve added one listener for each marker. Both of them save the new location of the marker (we can get that using the getPosition() function from the google maps api – the function returns the marker’s coordinates) and call the drawRoutes() function giving it the new locations as parameters.

In the drawRoutes() function we’ll have to find the addresses of the new locations and show the new line between the points and compute a new route.

To find the addresses of the points we’ll use the reverse geocoding feature provided by google maps. Geocoding means finding the coordinates of a given address, and reverse geocoding means finding the address of the points when you know the coordinates.

Here’s  the code for this:

[js]
geocoder = new google.maps.Geocoder(); // creating a new geocode object
if (geocoder)
{
geocoder.geocode({‘latLng’: location1}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
if (results[0])
{
address1 = results[0].formatted_address;
document.getElementById("address1").value = address1;
}
}
else
{
alert("Geocoder failed due to: " + status);
}
});
}

if (geocoder)
{
geocoder.geocode({‘latLng’: location2}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
if (results[0])
{
address2 = results[0].formatted_address;
document.getElementById("address2").value = address2;
continueShowRoute(location1, location2);
}
}
else
{
alert("Geocoder failed due to: " + status);
}
});
}
[/js]

The code is very similar to the code we’ve used to geocode the addresses. We’ve created a new geocoder object and called the geocode function as before. This time, the parameter we sent to the function is the location of the points. We’ve saved the result from the google server and the address1 and address2 variables. The address has the following format: “275-291 Bedford Ave, Brooklyn, NY 11211, USA”. We’ve written this address in the text fields from the form, so the user will know the exact address of the plotted points. We’ve used the document.getElementById() to set the values of the text fields. When both addresses are found, we call the continueShowRoute() function which shows the routes.

We’ll first show the line that connects the points. The difference from the first tutorial is that we now have to delete the last drawn line. Like this:

[js]
// hide last line
if (line)
{
line.setMap(null);
}
[/js]

Then we’ll draw the new one, just like before.

We’ll then compute the distance on a straight line between the points and show it on the screen, as I’ve shown in the first tutorial. The code to compute the quickest route and show the results on the screen also remains unchanged. The only thing we need to do is update the text on the infowindows with the new address values.

[js]
// update text in infowindows
var text1 = ‘

&lt;div&gt;’+&lt;/div&gt;


&lt;h1 id="firstHeading"&gt;First location’+

&lt;div id="bodyContent"&gt;’+
‘Coordinates: ‘+location1+’

‘+
‘Address: ‘+address1+’

‘+
‘&lt;/div&gt;

‘+
‘&lt;/div&gt;

‘;
var text2 = ‘

&lt;div&gt;’+&lt;/div&gt;


&lt;h1 id="firstHeading"&gt;Second location&lt;/h1&gt;

‘+

&lt;div id="bodyContent"&gt;’+
‘Coordinates: ‘+location2+’

‘+
‘Address: ‘+address2+’

‘+
‘&lt;/div&gt;

‘+
‘&lt;/div&gt;

‘;
infowindow1.setContent(text1);
infowindow2.setContent(text2);
[/js]

We’ve created new variables for holding the new texts to be shown in the infoboxes and used the setContent() function to change the texts on them.


Choosing the travel mode

We’ll also add the option to change the driving mode for the route shown on the map. The available travel modes are: driving, walking and bicycling (this option is only available for routes in the US).


We’ll first have to add a drop down box for the user to select the desired travel mode. We’ll add a new row to our previously created table:

[html]

&lt;tr&gt;

&lt;td&gt;Route type:
&lt;select id="&lt;span class="&gt;&lt;/select&gt;
&lt;option value="driving"&gt;driving&lt;/option&gt;
&lt;option value="walking"&gt;walking&lt;/option&gt;
&lt;option value="bicycling"&gt;bicycling (only in US)&lt;/option&gt;
&lt;/select&gt;
&lt;/td&gt;

&lt;/tr&gt;

[/html]

Now, let’s see what we have to do to show the selected travel mode correctly. We’ll have to change the options for the request we send to the directions service from google.

[js]
var travelmode = document.getElementById("travelMode").value;
// get the selected travel mode
if (travelmode == "driving")
travel = google.maps.DirectionsTravelMode.DRIVING;
else if (travelmode == "walking")
travel = google.maps.DirectionsTravelMode.WALKING;
else if (travelmode == "bicycling")
travel = google.maps.DirectionsTravelMode.BICYCLING;
// find and show route between the points
var request = {
origin:location1,
destination:location2,
travelMode: travel
};
[/js]

We’ve first saved the selected option from the drop down box in the travelmode variable. We’ve checked the value of this variable and set the travel variable that holds the google.map.travelmode. When setting the options for the request, we’ve used this variable to set the travel mode.


Saving the selected map setting

The map types the user can choose from are: roadmap, hybrid, satellite and terrain.


We’re going to use a hidden field in the form for holding the selected map

[html]
&lt;input id="&lt;span class=" /&gt;maptype" type="hidden" value="roadmap"/&gt;
[/html]

When creating the new map object, we’ll first check the value of this field and set the map type accordingly.

[js]
// get the map type value from the hidden field
var maptype = document.getElementById("maptype").value;
var typeId;
if (maptype == "roadmap")
typeId = google.maps.MapTypeId.ROADMAP;
else if (maptype == "hybrid")
typeId = google.maps.MapTypeId.HYBRID;
else if (maptype == "satellite")
typeId = google.maps.MapTypeId.SATELLITE;
else if (maptype == "terrain")
typeId = google.maps.MapTypeId.TERRAIN;

// set map options
var mapOptions =
{
zoom: 1,
center: latlng,
mapTypeId: typeId
};
[/js]

The last thing we need to do is update the hidden field value when the user changes the map type. For this, we need to add a listener that will be triggered when the user changes the map type. The listener will update the value of the hidden field.

[js]
// event listener to update the map type
google.maps.event.addListener(map, ‘maptypeid_changed’, function() {
maptype = map.getMapTypeId();
document.getElementById(‘maptype’).value = maptype;
});
[/js]

We’ve used the getMapTypeId() function to get the new map type and the document.getElementById() function to set the value for the hidden field.

And that’s it! We’ve finished improving our distance finder!

Editorial Team

Written by Editorial Team

77 Comments

  1. thank you so much.. this was exactly what I was looking for…

    Reply

    1. Happy to help, Mark! :)

      Reply

  2. Hi,

    I have translated your code to reflect my location reality. But regardless of the language, I am able to see the results of this coding on a web page but when entering addresses or places, there are no results posted when clicking on Calculate Distance button.

    Also I am wondering if the code could be adapted so as to take the distance result and to multiply it with a figure. I can provide you with a print screen of the modification required.

    Reply

  3. Excellent, fabulous..

    Reply

  4. Excellent, fabulous, Marvelous, Brilliant work
    So Easy, So Clear

    Reply

  5. A great tool and tutorial, but where do I put my google API key? I don’t want to use up your quota!
    many thanks.

    Reply

  6. Hi, this is a great tutorial and tool, but was wondering where do I put my google API key? I don’t want to use up your quota! :)

    Reply

  7. good job
    it is my question too”Hi, your tutorial is excellent but may i know how do i calculate the distance for 5 markers ??”

    thanks for sharing

    Reply

  8. Hi, your tutorial is excellent but may i know how do i calculate the distance for 5 markers ??

    Reply

  9. The best tutorial ever.. Thank you so much for this. :)

    Reply

  10. Very innovative, great article. Cheeers :)

    Reply

  11. thanks very very much Irina Borozan, application is perfect. hehe

    Reply

  12. Hi,
    Thanks a lot for detailed tutorial. I was wondering If we can add hundreds of addresses or load result from excel/google spreadsheet (colum A is source and Column B is destination). It will be much appreciated if you can propose any solution.
    Thanks

    Reply

  13. This is really a GREAT tutorial! Thank you very much Irina!

    Reply

  14. Hi,
    Very nice article, is there any usage limit that apply per month/per day.

    Reply

  15. Hi, Thanks for your detailed explanation. I think you can help me. I am trying to draw a path based on a set of geo coordinates on my own map(not google maps) but I do not know how to create the path. Does google maps API support a function in which the returning result is a path(probably a set of lines)?

    Reply

  16. i want to do same in visual basic application..please help me..i almost done with my app,but i cant do the exact thing in vb form..(im using vb 6) your help highly appreciated,thank you.

    Reply

    1. Did you ever figure this out? I’m trying to do a similar thing. I want to enter 2 addresses on a form, click a button and have the distance insert into a separate text box on the form. I’m using Visual Basic Express 2010.

      Reply

  17. it’s cool, thanks a lot

    Reply

  18. I am trying to convert it into Miles but :( not getting any success plz anyone can help me out………

    Reply

    1. Sumeet jaiswal February 2, 2016 at 07:57

      multiply the distance in km*1.6.and then show it in miles.

      Reply

  19. Hi, greaet work.

    How can we Build a Distance Finder with Google Maps API between two zipcodes.

    Reply

  20. Very nice, thanks for all the hard work. One question though. The “straight line distance” is always greater than the “chosen route” which seems to agree with Google Maps. How can the straight line distance be greater than a route that must follow roads and streets?

    Reply

  21. Great tutorial. Keep the good work up.

    Reply

  22. Hello,
    nice tutorial, and i implement it very easily in my site.
    I want 1 thing more, the distance between the cities are showing in English How can I show the distance in other languages. i need Portuguese Language.
    thanks in advace

    Reply

    1. Hi

      You can find an example of how to loads the map in other languages here: http://code.google.com/apis/maps/documentation/javascript/basics.html#Localization

      Reply

  23. hiya,

    I would say its wonderful tutorial I have came across, I was just wondering if you can give an idea how can I create random markers between start and end location. lets say start and end location is same and I want to put three way points randomly in such a way that I can control the duration of distance between start and end point. like if way points are placed randomly and I ckeck if distance is greater than 1 hour then reduce distance to one hour.

    I would really appreciate if you can propose a solution

    Reply

    1. Hi

      Yes, this could be done. You will have to add one more point on the route. Actually 3 points, and recompute the route via each of those and check the results :)

      Reply

  24. Great tutorial thank you very much, I was wondering if there was a way of adding the fuel cost into it? Cant seem to find anything on the api!

    Reply

    1. Hi

      There’s nothing like that in the api, but you could add something. You get the distance from the api, use a variable for the fuel cost and compute the result :)

      Reply

  25. Hi Irina,

    Great document very helpful for me and my project but i have a question:

    Is it possible to work out the distance im miles rather than KM?
    Is it possible to work out the round distance ie there and back? i am creating a mileage tracking system that would track the distance for the full journey.

    Reply

  26. superbbbbbbbb….. thanxs alot…. really best….

    Reply

  27. First Thanks a lot for such a superb helpful stuff.
    now here I need something more,
    like:”I want to offer the choose the way from Suggested routes(not by default shortest one)”.
    so its possible,please if it possible help me,
    thanks in advance….

    Thanks & Regards,
    Kalpesh

    Reply

  28. Hello. I was playing on your aplication and I found a small error. When You click show the aplication displays the map properly. But when You do it again (doesn’t matter if you change the location) map shows whole world and the javascript error occurs. I was trying to fix it. If you change the default zoom parameter from 1 to 2 it works perfect. I don’t know why exacly but it does.

    Thanks alot for this tutorial. It was very helpful for me.

    Reply

    1. I’m glad you liked it! I will check out the error you mentioned.

      Reply

  29. Hi Irina,

    Thanx a million for writing such an wonderful Google map tutorial! It is very good and well explained tutorial. Looking forward to read the second part. :)

    One thing I just can’t understand. Where to use the KEY which Google gives in the sign-up page? (I’m just a starter! :) )

    Reply

    1. I’m glad you liked it! Google maps api v3 doesn’t require an api key anymore :)

      Reply

  30. Awesome tut….very helpful in daily life…also very innovative….

    Reply

  31. Great tuto! Thanks! For Spanish people, try to find the rou from “Vete” to “Cagar”, it exists!

    ;-)

    Reply

  32. Great !! Thanks to you…

    Reply

  33. very nice thanks but how do i output distance in miles and not km ? is it possible

    Reply

    1. You would just have to compute the return values from gmaps from kms to miles :)

      Reply

  34. Hi Irina

    What an awesome tutorial thank you. Pehaps you can point me in the right direction:

    When a user starts typing in an address i would like it to automatically dropdown a suggested list of addresses. The same as it works for google map directions.

    If you can point me in the right direction It would be greatly appreciated.

    thanks
    Ryan

    Reply

    1. Hello

      You would need to use some code for that auto-complete. There are loads of libraries (in javascript, jquery) available. Here’s an example:

      The library you choose to use depends on the programming language your app is written in and on the location of the data you want to show in the drop down.

      I hope this helps!

      Reply

  35. Hi Irina

    Do you know how i can get the google formatted address? Basically take the address entered and get the address back from google formatted correctly?

    Thanks in advance
    Ryan

    Reply

    1. Hello

      That’s a really good idea! I haven’t thought of doing this before, but I will definitely look into it. I don’t know if there are any converters available though. You might need to write your own.

      I’ll let you know if I find anything useful!

      Reply

  36. very nice and very usable!!!
    a little hint: why don’t u convert the distance in a more useful way? i.e. in km

    Reply

  37. it`s great lesson!
    thanks.

    Reply

  38. Hey. Great tutorial. I have always used google maps. Its interesting to see that there is lot more to it.

    Reply

  39. Irina,Good work!
    I wanna to know if it could show the bus line!?

    Reply

    1. I will have to look. But I think so, but only for some cities. Check here: http://maps.google.com/help/maps/transit/

      Reply

  40. Hi!
    Yep, Nice article, helped me alot.

    Thanks.

    Reply

    1. I’m glad you liked it!

      Reply

  41. i had to do this time ago for a website.
    don’t store the address, but use the lat and the long instead

    first of all i looped a php page that reads the addresses from the db, find lat and long via google geolocation and then store it into the db. starting from this moment you can always geolocate the point in the google maps reading its coordinates

    Reply

    1. That’s a good idea!

      Reply

  42. Omer Rosenbaum June 30, 2010 at 14:15

    Hi Irina!
    Great stuff you made there. I want to continue developing it and combine it with MySql.
    What I am trying to do is to get the 2 addresses into a DB. So far I haven’t had much success. Could you or anyone else can try to prepare such thing?

    Reply

    1. That’s a good idea! I am probably going to write another tutorial on google maps and I could also add this to it.

      In the meantime, if you need some help with what you’ve tried so far, send me a message or something and I could help you.

      Reply

  43. Thank you all for the tips and ideas! I might be adding some to my next google maps tutorial :)

    Reply

  44. Shawn McConnell June 30, 2010 at 05:25

    Irina, nice tutorial I have done something similar on my site but I just outline the locations of where I have previously worked on my resume page. this helps potential people see the general area I work in.

    Shawn,

    Reply

    1. Thats a good idea of using google maps! :)

      Reply

  45. I’ve just found out google maps turns 5 today! Nice coincidence!

    They’ve made a map with applications made by users and I’ve added mine there :)

    Reply

  46. Multumesc pentru tutorial. Daca se poate traseu si cu ruta din 1, 2 puncte de trecere.
    Emil

    Reply

    1. Bună idee :)

      It’s not very difficult to add more points on a route as you said, you just have to multiply to code for the textboxes and markers :)

      Reply

  47. Really awesome Tut Irina. Thumbs up. :)

    Reply

  48. Very interesting, You should complete it adding driving directions!

    Reply

    1. Stay Tuned for the 2nd part coming on Thursday.:)

      Reply

  49. Nice tutorial! One question: why do you set the zoom level at 1? Wouldn’t it be better to make the zoom level high enough to show just the area with the two points defined by the user?

    Reply

    1. I’ve left it at 1 because if google can find a route between the two addresses, it automatically adjusts the zoom level when showing the route.

      Reply

      1. Ah, excellent. Thanks!

        Reply

  50. Frank Bailey June 29, 2010 at 19:39

    Hi Irina, this is a great tutorial, thanks a ton! I’d just like to know if you might be able to provide a quick example of how we might be able to allow the user to click a point on the map to use as either the destination or origin, rather than entering and then geocoding the address?

    Reply

    1. Hey, good idea! You’ll see something similar to this in the second part of the tutorial, which will be posted in a couple of days ;) I’m glad you enjoyed this one!

      Reply

  51. Hi!
    Very nice article, a small digression, you don’t need an API key if you’re using Googla Maps API v3. (You also didn’t use an API key in example provided with post.)
    Regards

    Reply

  52. Thanks for all the comments and tips! I’m glad you like it :)

    Reply

  53. this is very nice post

    Reply

  54. THANKS!!! It is an excellent tutorial.

    Reply

  55. Nice tut! Thanks.
    I saw a website using Google Maps like your tutorial, providing this kind of tool: http://distancity.com

    Reply

Leave a Reply