Home

Coordinates

Latitude:    Longitude:

Drag the marker on the map to set the coordinates:

Top

Concept

Coming soon.

Top

How It Works

Coming soon.

Top

Download

Coming soon.

Comments

Blank Avatar
Paulo Antunes
22 December 2007


Hi Ben,
Great application!!
I was looking for to get coordinates by an street address.
Is this available? for free access.
I'm trying to find some street address coordinates to see them in Google Earth.
Would you give me any hint on how to get this?
Merry Christmas!
Paulo Antunes - +55 11 9135 5188
São Paulo - Brazil

Blank Avatar
Ben
26 December 2007


hi paulo, i will be posting this in the (hopefully) near future. in the meantime, here is a link to the google maps geocoder, which can be used to get coordinates from addresses:

http://code.google.com/apis/maps/documentation/services.html#Geocoding

good luck!

Blank Avatar
Andrew (Ireland)
27 December 2007


well done on a great site. I've been looking for this kind of simple functionality for some time and to date I was jumping between a couple
of sites in order to find coordinates for geocaching etc. It might be a nice idea to add a page for converting different formats for coordinates also. These are readily available but it might be useful to have it in your site also. Thanks

Blank Avatar
Mark Bowen
12 May 2008


Hi Ben,

This looks really interesting. Well done on it. Just to answer the other question about getting co-ordinates for an address there is a way to do it without using any of the APIs if you want to. It involves going to the address in [url="http://maps.google.com"]Google Maps[/url] that you want to find the co-ordinates for and then using the following Javascript in your browser [i](make this a bookmark so that you can use it quickly)[/i]

[code]
javasc*ipt:void(prompt('',gApplication.getMap().getCenter()))
[/code]
[i]I have taken out a few of the letters above so that hopefully the code will show here. Hopefully it should be obvious what to replace the [b]*[/b] symbols with but if not then just get in touch with me and I can send you a file with the code in instead[/i]

Hope that helps.

Best wishes,

Mark

Blank Avatar
steve hess
30 May 2008


Hi Mark,
i am trying to use this concept...but allow users to give me their address first as the starting point...versus a hardcoded lat/lon. would you be willing to send me the script that would allow for that users input?

Blank Avatar
Ben
30 May 2008


hi steve,

i assume your question was directed at me? here is how i would do it.

address = "Dublin, Ireland";

geocoder = new GClientGeocoder();

geocoder.getLatLng(address,  
  function(point) {
    if (!point) {
      alert(address + " not found");
    } 
    else {  
      // set centre of map and add marker to centre of map and make it draggable
      map.setCenter(point, 12);
      var marker = new GMarker(point, {draggable: true});
      map.addOverlay(marker);
    
      // add listener to marker
      GEvent.addListener(marker, "dragend", function() {
        var point = marker.getPoint();
        map.panTo(point);
        document.getElementById("latitude").value = point.lat();
        document.getElementById("longitude").value = point.lng();
      });
    }
  }
);

Blank Avatar
steve hess
30 May 2008


Hi Ben and thanks for the fast response! being a novice at this, could you show your code within the script tags in their entirety? not sure what to replace with your code. thanks again!

Blank Avatar
steve hess
30 May 2008


actually...scratch that...but question:

by leaving all else the same except for accepting a variable address, how does that affect this concept...it doesn't set the initial lat/lon in the form or change the center point. did that make sense?



<!--
if (GBrowserIsCompatible())
{
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());

if ("34.051" == "" || "-84.071" == "")
{



var address = "<% request.querystring("address")%>";

var geocoder = new GClientGeocoder();

geocoder.getLatLng(address,
function(point) {
if (!point) {
alert(address + " not found");
}
else {
// set centre of map and add marker to centre of map and make it draggable
map.setCenter(point, 12);
var marker = new GMarker(point, {draggable: true});
map.addOverlay(marker);

// add listener to marker
GEvent.addListener(marker, "dragend", function() {
var point = marker.getPoint();
map.panTo(point);
document.getElementById("latitude").value = point.lat();
document.getElementById("longitude").value = point.lng();








});
}
});
}

else
{
var centrePoint = new GLatLng('34.051', '-84.071');
map.setCenter(centrePoint, 16);

var marker = new GMarker(centrePoint, {draggable: true});
map.addOverlay(marker);

GEvent.addListener(marker, "dragend", function() {
var point = marker.getPoint();
map.panTo(point);
document.getElementById("latitude").value = point.lat();
document.getElementById("longitude").value = point.lng();
});
}
}
//-->
</SCRIPT>

Blank Avatar
Ben
30 May 2008


it will set the center point of the map to the address. in your code above this will only happen if either the latitude or longitude is blank. so the important line is:

if ("34.051" == "" || "-84.071" == "")

Blank Avatar
steve hess
30 May 2008


ok...gotcha...so i remove the lat/lon and the center point is now set.

so then is there a way to auto adjust the form fields so that the user doesn't need to move the marker for the form to recognize the center point coordinates?

Blank Avatar
Ben
30 May 2008


just add the following lines under map.setCenter(centrePoint, 16)

document.getElementById("latitude").value = point.lat();
document.getElementById("longitude").value = point.lng();

Blank Avatar
steve hess
30 May 2008


so close....I owe you Ben!

the form isn't taking new coordinates unless i move the marker. basically, i'm using a query pull the persons address...and have the form use the lat/lon from that as if they had dragged the marker....versus using the forms initial values. does that make sense?

here's my url:
http://66.155.125.63/maps_getcoordinates4.asp?address=atlanta, ga



here's the script:




if (GBrowserIsCompatible())
{
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());

if ("" == "" || "" == "")
{



var address = "<%=request.querystring("address")%>";

var geocoder = new GClientGeocoder();

geocoder.getLatLng(address,
function(point) {
if (!point) {
alert(address + " not found");
}
else {
// set centre of map and add marker to centre of map and make it draggable
map.setCenter(point, 12);
var marker = new GMarker(point, {draggable: true});
map.addOverlay(marker);

// add listener to marker
GEvent.addListener(marker, "dragend", function() {
var point = marker.getPoint();
map.panTo(point);
document.getElementById("latitude").value = point.lat();
document.getElementById("longitude").value = point.lng();
});
}
});
}

else
{
var centrePoint = new GLatLng('34.051', '-84.071');
map.setCenter(centrePoint, 16);
document.getElementById("latitude").value = point.lat();
document.getElementById("longitude").value = point.lng();


var marker = new GMarker(centrePoint, {draggable: true});
map.addOverlay(marker);

GEvent.addListener(marker, "dragend", function() {
var point = marker.getPoint();
map.panTo(point);
document.getElementById("latitude").value = point.lat();
document.getElementById("longitude").value = point.lng();
});
}
}

Blank Avatar
Ben
30 May 2008


it should be:

document.getElementById("latitude").value = centrePoint.lat();
document.getElementById("longitude").value = centrePoint.lng();


Leave A Comment

name (required)
email (required but will be kept completely private)
website