I am a software and web developer. This is my personal projects website. Most of the projects are ExpressionEngine add-ons and useful little applications written in php and javascript.
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
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:
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
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]
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?
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();
});
}
}
);
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!
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>
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:
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?
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();
});
}
}
Comments
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
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!
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
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
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?
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(); }); } } );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!
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>
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" == "")
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?
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();
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();
});
}
}
Ben
30 May 2008
it should be:
document.getElementById("latitude").value = centrePoint.lat();
document.getElementById("longitude").value = centrePoint.lng();
Leave A Comment