December 27, 2006
Geocoding Tool for Virtual Earth & Google Maps
Would you like to be able to geocode Virtual Earth and/or Google Maps without the hassle? Or how about any application requiring the use of javascript?
Well, you can use this API for it:
It is a javascript API and you can call it like so:
The base URL is:
http://geo.localsearchmaps.com/
To enter a freeform location (you have one entry box that accepts any address format such as street address, zipcode, city/state, etc):
http://geo.localsearchmaps.com/?loc=1600+Amphitheatre+Parkway,+Mountai n+View+CA++94043
In other words, just use the “loc” parameter. Currently, only the US is supported for freeforms….I have to decode all potential formats for non-US addresses.
If you would like more accuracy (or international support), break the text entry fields up into multiple fields. Mix and match and use whichever you’d like from the following parameters:
address (street address)
city
state
zip
some examples:
http://geo.localsearchmaps.com/?city=burbank&state=ca
http://geo.localsearchmaps.com/?zip=90069
http://geo.localsearchmaps.com/?street=48+Leicester+Square&city=London &country=UK
http://geo.localsearchmaps.com/?city=sydney&country=au
The default URLs above are for the Google Maps API. To use the Virtual Earth API, construct the URL the same as you would above and add the following parameter “&ve=1″ … for example,
http://geo.localsearchmaps.com/?city=burbank&state=ca&ve=1
http://geo.localsearchmaps.com/?loc=1600+Amphitheatre+Parkway,+Mountai n+View+CA++94043&ve=1
Alternatively, if you choose to use neither Google Maps nor Virtual Earth (or to have better control to do what you want), you can set a callback parameter with ‘cb=<MethodName>’ like so:
http://geo.localsearchmaps.com/?city=hollywood&state=ca&cb=MyJavascrip tMethod
Some intillegence is there to try to guess the appropriate one…however, if you prefer to override it with your own, you can add the parameter “level=
For example:
http://geo.localsearchmaps.com/?city=burbank&state=ca yields Google Maps zoom level 4
but you can force it to zoom level 1 by using this url:
http://geo.localsearchmaps.com/?city=burbank&state=ca&level=1
Default behavior is for an alert to happen onerror (currently there are only 2 errors: ‘location not found’ and ‘Please provide a location’). To override this behavior, you can specify a callback for errors by adding a parameter ‘cbe=<function_name>’
For example, the first link below will provide an alert error but the second one will use the specified callback:
http://geo.localsearchmaps.com/
http://geo.localsearchmaps.com/?cbe=MyError
If you are not very familiar with javascript and how to leverage this, you can take a look at some of the source of some of the sites using them:
Virtual Earth example
Google Maps Example
Basically, you’ll either use a “script src=<URL>” or
var s = document.createElement( “script” );
s.src=<URL>;
s.type = “text/javascript”;
document.getElementsByTagName( “head” )[0].appendChild(s);
Recommendations? Errors? Feature requests? Post them here and I’ll try and fix/add.
UPDATE: You can now lookup information and geocode by IP Address.
To lookup by the requesting IP address, just add “by_ip=1″ like so:
http://geo.localsearchmaps.com/?by_ip=1
To get city/state info, use a callback:
http://geo.localsearchmaps.com/?by_ip=1&cb=IpLookup
To lookup an IP address by passing it in, rather than using the requestor’s ip:
http://geo.localsearchmaps.com/?by_ip=1&cb=IpLookup&IP=66.249.66.98
Keep in mind, when using IP addresses, that this info isn’t always very good and, in fact, many IP addresses will not have any data. I have built it in to try looking up by IP address when the by_ip=1 parameter is used but to fall back on the other lookup info (i.e. loc or city infor passed in) if the IP address lookup fails.
To try it out, check out the virtual earth or google earth geourl sites and click on the “Guess by my IP Address” link.
UPDATE: API now supports &phone= as well as &format=.
The phone parameter tries doing a reverse lookup to find an address then geocodes that address for you.
The format parameter accepts “XML” or “json” to output in those corresponding formats. Here is an example utilizing both of these features:
http://geo.localsearchmaps.com/?phone=8188463111&format=json
The above is a lookup of the Burbank Chamber of Commerce phone number.
So what am I asking in return for use of this tool?
Well, I’m asking (but not requiring) a reciprocal link to either the localsearchmaps.com homepage or to this blog’s homepage.
Any usage limitations?
Well, if you overburden this server, I might throttle you or even shut you down if you abuse it (never happened yet!). If you think you are blocked, feel free to email me and I will unblock you as long as we clear up any issues.
UPDATE: I have added a new feature as of 2004/02/24. You can now do a reverse lookup of lat/long to address. It currently is much more limited in area and in accuracy than other components of this framework and its performance/response time is not that great yet so use with caution and I will improve over time (feedback always welcome).
To use it, just specify a latitude and longitude in your request like so:
http://geo.localsearchmaps.com/?format=json&lat=34.209539&long=-118.32 5116
Like this service? Help make sure it keeps a good level of service (or even improves it) by donating:
… or how about just a link back to me or localsearchmaps.com?

(12 votes, average: 4.75 out of 5)






James Weisbin said,
August 16, 2005 @ 11:23 am
I would like to be able to just point a browser to maps.google.com?address=, without having a web site of my own. Is there a way to do this?
Thanks
emad said,
August 16, 2005 @ 12:24 pm
James,
Try something like this:
http://maps.google.com/?q=burbank,+ca
James Weisbin said,
August 16, 2005 @ 1:25 pm
Thanks!
James Weisbin said,
August 16, 2005 @ 1:59 pm
Is this getting a query string? I don’t understand how this works:
document.getElementsByTagName( “head� )[0].appendChild(s);
I’m trying to use the query string to append to the localsearchmaps URL as you’ve done above, but this doesn’t work (I’v already set up a web page with a google maps ID, that part is working), and QueryString is parsed elsewhere
function go_to_url() {
var queries = QueryString(’loc’);
var url1 = “http://www.localsearchmaps.com/geo/?loc=”+queries
var temp1 = “”
var temp3 = temp1 + url1 + temp2
document.write(temp3)
emad said,
August 17, 2005 @ 7:25 pm
this: document.getElementsByTagName( “head� )[0].appendChild(s);
is appending the javascript to you created in the object named “s” at the end of the “” tags…just remember to use the entire snippet provided above to create that object.
This API is meant to be called as an external javascript file.
Once you’ve created the url:
var url1 = “http://www.localsearchmaps.com/geo/?loc=�+queries
You can either use the document.getElementsByTagName( “head� )[0].appendChild(s) method or you can do a:
document.write(”);
If you want more help, and are willing to provide your URL, email it to me or post it here and I’ll be glad to help.
Good luck!
Emad Fanous » Blog Archive » New features in Geocoding API said,
August 23, 2005 @ 1:56 pm
[…] I have added a new feature in the geocoding API. […]
emad said,
September 1, 2005 @ 2:48 pm
I was asked by Arsen Vladimirskiy who asked what the source of the geocoding was.
My geocoding leverages multiple freely available sources that any of you could build. This API was made for those who don’t want to go through the hassle of 1, let alone all of them.
The sources include many I’ve mentioned here but am too lazy to write and put links for (so go to that entry to get them).
I then weight the different sources based on their reliability/accuracy based on experience and algorithmically to get the best results (i.e. many of those sources are national US only, etc). I then fall back to the next most reliable if the geocoded info isn’t available.
Emad Fanous » Blog Archive » MSN opens APIs to many of its products said,
September 9, 2005 @ 9:03 am
[…] I had created some VE apps…they had launched viavirtualearth.com, which I had used to create them…but now MSN has launched an API developer site to encompass more products. […]
Mel said,
October 5, 2005 @ 9:14 am
Thanks for building this!
I’m having a hard time figuring out how this should work wil the whole
//
…thing.
How do I get the correct “map.center….” in there?
dense,
mel
Mel said,
October 5, 2005 @ 9:15 am
hmmm…the comments didn’t like my copy paste…here goes again:
function createMap(){ var map = new GMap(document.getElementById(”map”));
map.addControl(new GSmallMapControl());
map.centerAndZoom(new GPoint(-74.005565,40.739101), 2);
var point = new GPoint(-74.005565,40.739101);
var marker = new GMarker(point);
map.addOverlay(marker);
}window.onload=createMap;
emad said,
October 5, 2005 @ 9:36 am
Hi Mel,
I think this might be what you’re looking for (untested):
View source of this page.
Mel said,
October 5, 2005 @ 9:52 am
actually, no.
i’m trying to get the results from http://www.localsearchmaps.com/geo/?loc=query to appear within in js that draws the gmap…
This:
function createMap(){ var map = new GMap(document.getElementById(”map”));
map.addControl(new GSmallMapControl());
var s = document.createElement( “script” );
s.rc=”http://www.localsearchmaps.com/geo/?loc=query”;
s.type = “text/javascript”;
document.getElementsByTagName( “head” )[0].appendChild(s);
var marker = new GMarker(point);
map.addOverlay(marker);
}window.onload=createMap;
does nothing for me…
the s.rc shows the correct address to query, but how do i get back that essential line, “map.centerAndZoom(new GPoint(-83.7458, 42.2833), 4);”
is that more clear?
emad said,
October 5, 2005 @ 10:16 am
Mel,
Try replacing:
s.rc
with
s.src
Mel said,
October 5, 2005 @ 10:24 am
this still returns a big grey map:
(sorry! and thanks sooo much!)
function createMap(){
var map = new GMap(document.getElementById(”map”));
map.addControl(new GSmallMapControl());
var s = document.createElement( “script” );
s.src=”http://www.localsearchmaps.com/geo/?loc=Ann%20Arbor,%20MI%20481 09″;
s.type = “text/javascript”;
document.getElementsByTagName( “head” )[0].appendChild(s);
var marker = new GMarker(point);
map.addOverlay(marker);
}window.onload=createMap;
emad said,
October 5, 2005 @ 10:36 am
np!
check out the source to this page (don’t forget to replace the google API key with yours when you download it).
A few things:
1. when adding a marker, you have not defined the variable called “point.” To add one, use “var point = new GPoint(xcoord,ycoord);”
2. You needed to properly scope the “map” variable. So I scoped it outside of the createMap function so other things outside of that method can access/use it
George Agh said,
November 5, 2005 @ 10:03 am
Hi Emad, hi all
great API, still very long respond.
It’s possible to call a function after loading the script?
What I mean: when I call like this
http://www.localsearchmaps.com/geo/?zip=AAAA&MyFunction=FunctionName
the returned script to be:
map.centerAndZoom(new GPoint(-118.3811, 34.0919), 4);
FunctionName();
/Thanks
George Agh said,
November 5, 2005 @ 10:10 am
This feature would help because of the long time for responding. When the page make the call, can showup a ‘LOADING’ message, and after loding to hide it.
For now, the user click it and wait.. and wait… without knowing what’s happening.
Emad Fanous » Developing with Maps and Geocoding said,
November 10, 2005 @ 11:29 am
[…] Many have been interested in my free geocoder but, with the launch of their new API, it looks like Yahoo is providing geocoding APIs, APIs to stitch together maps for offline/mobile use (remember when Google prevented someone from doing that?), etc: […]
edgar panaguiton said,
February 14, 2006 @ 6:34 am
emad,
i want you to know that your work is VERY VERY much appreciated by developers like us.
thanx!
edgar
Mike Engel said,
March 1, 2006 @ 11:13 pm
My map displays correctly using the appendChild method you demonstrate. My question is, how do I get the x and y coordinates from that to use in creating my marker?
d`arcy said,
March 14, 2006 @ 8:46 pm
Thanks for the service Emad, it works like a charm (although the data for my country is pretty inaccurate, but I believe that’s my ISP’s fault).
Mike, you could try using some PHP, like this:
$query = “zip=12345″;
$info = file_get_contents(”http://www.localsearchmaps.com/geo/?$query”);
and then parsing $info to get the coords, and use them elsewhere on your page.
Emad Fanous » Free GeoSpatial and MBR Search said,
March 16, 2006 @ 12:52 pm
[…] Here’s a new tool for those who are having problems using the geocoding tool or would just like a simple way to set up a geospatial search: […]
Humberto said,
April 8, 2006 @ 4:24 pm
A very good work. The best I have seen.
What contry codes do you use, ISO or FIPS?
emad said,
April 8, 2006 @ 9:22 pm
Hi Humberto.
Thanks! This tool uses ISO country codes but I try to transalte country names as well.
http://www.localsearchmaps.com/geo/?format=json&country=Spain&city=Mad rid
http://www.localsearchmaps.com/geo/?format=json&country=ES&city=Madrid
Please let me know if there are countries that aren’t getting translated.
TODO: handle FIPS country codes as well.
(assuming no collision between ISO and FIPS mapping the same 2 characters to different countries).
Humberto said,
April 9, 2006 @ 5:29 am
Thanks for your reply.
There are collision bettween ISO and FIPS codes - e.g. AS is American Samoa in ISO and Australia in FIPS. So better keep only one standar.
About country names. I have try some names and for some it works even if I try the names in my native language (portuguese) others doesn’t work neither with native names and english names.
So my opinion is: use only one country codes standar and let your users use the country names in what language they want and passe the code to your tool.
Best regards
Humberto said,
April 9, 2006 @ 6:03 am
Hi, again.
After some research it seems you are using ISO 3166-1 alpha-2 wher thw code for East Timor transitional reservation TP ( the code your recognize), but now the code is TL.
Making a search for Dili (East Timor capital) with country code TP the results are correct, using TL gives a place somwhere in New Mexico USA.
Thanks and keep going
David said,
April 9, 2006 @ 8:57 pm
Hi,
We at siteclash.com were trying to use your service for geocoding, however your web app was down for some time on the 11th of April. Does your app go down a lot? Thanks for providing this service.
emad said,
April 9, 2006 @ 9:12 pm
Hi David,
The service wasn’t actually down…the problem was with an upstream network provider. Depending on where you were located, you might have experienced network slowness trying to communicate with my servers.
Site availability has always been good (even when the problem is out of my hands due to upstream providers). I’ve always monitored my site (even before this service was launched) to create the best possible availability…but understand this is a free service.
I have and will continue to improve availability…All my sites and services will be expanding to a load-balanced environment across 2 completely different network environments. This will hopefully eliminate all availability issues since I will have a fully redundant copy of all my applications and data in 2 completely different locations. My timeline for this is within 3-4 months. In the meantime, like I said, the availability of the site is pretty good.
Alan K said,
April 19, 2006 @ 2:35 pm
Hi Emad,
Thanks for the tool - it is very useful, but since I upgraded my Google Map API from version 1 to version 2, I think the Longitude and Latitude are appearing in the wrong order (IE. they appear currently as latitude-longitude, when it should now be longitude-latitude). Any ideas on how I can switch this around?
Thanks, Alan
Alan K said,
April 19, 2006 @ 2:46 pm
In fact, looking into it further, Google have changed alot of the functions. And so, if you are using the new Google Map version 2 output should look something like this:
map.setCenter(new GLatLng(51.5063, -0.1271), 1);
emad said,
April 19, 2006 @ 3:12 pm
Good point, Alan!
I have now created another type “google2″
so, you can append the parameter “&use=google2” to the URL (or “google” or “ve”) or you can specify it the same way you do above “&google2=1”
your choice on which to use.
Alan K said,
April 19, 2006 @ 3:19 pm
Great! Many thanks.
Phill said,
April 25, 2006 @ 9:16 am
Just to let you know…your output is:
map.setCenter(new GLatLng(”34.1003, -118.3271″), 4);
It should have no perentecies
thanks
emad said,
April 25, 2006 @ 7:58 pm
Thanks, Phil….fixed!
Ben said,
May 4, 2006 @ 11:46 pm
Exactly what I was looking for! Thanks, Emad!
One issue I came across: Safari has problems with “long” when using dot notation with the returned json data.
For example, if I assign the json result to the variable “jsonResult”, referring to “jsonResult.long” causes Safari to generate a “SyntaxError - Parse error” and aborts the whole page. On the other hand, using jsonResult[”long”] works fine.
Rob Sosnowski said,
May 7, 2006 @ 5:42 am
Nice work.
I’ve entered a few addresses within an MS IE browser window:
http://www.localsearchmaps.com/geo/?street=1+zzzz+Ln&city=Boise&countr y=Id
http://www.localsearchmaps.com/geo/?street=1+zzzz+Ln&zip=83714
In both cases a location is returned instead of “Address not Found” or some indicator like that. I’d like to screen out invalid addresses - How do I do that?
Thanks, Rob
emad said,
May 7, 2006 @ 6:38 am
Thanks, Ben.
I don’t want to break functionality for others using this API so instead of changing it, you’ll need to append another value:
If you add fn=1 to your call, I will use “full names” for latitude and longitude.
http://www.localsearchmaps.com/geo/?city=sydney&country=au&fn=1&format =json
emad said,
May 7, 2006 @ 6:46 am
Rob,
You are getting the “best possible” match for your entry.
In your first example, you are supplying a valid zipcode of 83714 so you are getting a zipcode-level match against that zipcode.
This type of behavior allows for the best possible experience for you user.
You can, however, get more access to information about the geocoding. If you use the json or XML output, you get a level or matchlevel parameter, respectively (and other extended data). These tell you how good the match was.
Jamie Johnson said,
May 9, 2006 @ 8:40 pm
Is there a way to just get back the x and y coordinates for the latitude an longitude? I assume I need those for the var point = new GPoint(xcoord,ycoord); line so I can get the marker to appear on the page. I figure I could parse those coordinates out of what you return in http://www.localsearchmaps.com/geo/?loc= but I thought there might be an easier way.
Love your tools!
Jochen said,
June 7, 2006 @ 5:20 am
Hi,
this is a cool tool, is it possible to use it for a batch geocoding?
Greetings Jo
emad said,
June 7, 2006 @ 6:26 am
Hi Jochen,
While I wasn’t originally sure if I wanted to support it because it was originally running off of my DSL line and could easily chew up my bandwidth, I let people go ahead and do it as long as they paced out their requests a bit.
However, I have now moved my application to a dedicated host and will “officially” support it.
In other words, go ahead!
If the data you want batch-geocoded is large, feel free to contact me about sending me a file and having the geocoding done locally on the machine, then have the results returned to you. This can be faster for large data sets since you avoid the network overhead on each request.
Stu Rayner said,
June 23, 2006 @ 5:13 am
Great service, just what I was looking for! Reall pleased you can do UK postcode lookups as well as US zips.
Rather than using the include file suggested above, I plan to make HTTP calls via AJAX. If I use a custom callback method name, all I need to do is evaluate the response text.
Excellent!
emad said,
June 23, 2006 @ 6:05 am
Glad you like it Stu. Just as an FYI, I like using the JSON calls with AJAX. The output can be eval’ed or parsed within javascript.
emad said,
August 29, 2006 @ 9:45 am
Too many people are scraping the site, doing bulk geocoding without giving notice and other sites (like this blog) have suffered in performance because of it.
I have moved this to its own server. Please start using http://geo.localsearchmaps.com instead of http://www.localsearchmaps.com/geo … the guide above has been updated.
Ryan said,
September 6, 2006 @ 2:52 pm
Hi, I am the author of phpGoogleStoreLocator, an open source project that utilizes the googlemaps API as well as yahoo and geocode.ca for geocoding addresses in the US/Canada. I’ve been searching for a UK geocoder (as well as Australia) for about 8 months now and had absolutely no success what so ever at finding a free one until now. I wanted to know if you would have any objections to me adding your geocoder to my application for my user base to use. I noticed it does more than just the UK and would be interested to know if there are any hit per day limitations I need to let them know about and what other countries it is capable of geocoding. I wish I could have found your site sooner, but I just stumbled upon it today.
jonnii said,
September 18, 2006 @ 2:01 pm
I was wondering why my unit tests suddenly start failing for the locating! I think it’s a good idea that you changed the URI to stop people from scraping the site. Just so you know i’m using it for my site www.pumpqin.com and have so far probably only requested about 10 sets of coords =)
I’m going to be giving you a plug in my about page.
Have you considered maybe implementing some kind of API-key system to make sure people register in order to use the service? Might stop people leaching…
emad said,
December 14, 2006 @ 8:56 am
mathieu Gosselin is using this service with his yahoo maps application in flash. He emailed to tell me that it wasn’t working and asked if I had blocked his IP Address since he could reach it in his browser but not within the application.
I did a bit of research and found that flash applications make requests to crossdomain.xml from the intended target URI of a domain to make sure that applications that exist outside of a domain can access services from that domain.
Since, I didn’t have one, the flash application would not make the request to the geocoding URL. I have gone ahead and created this file and made it universally accessible by all domains. Feel free to utilize your flash applications with this tool.
Thanks, Mathieu!
David Pride said,
February 19, 2007 @ 6:55 am
Hi there - superb piece of coding! Been looking for a postcode to lat long geocoder that a. doesn’t cost a fortune and b. is a piece if cake to use.
Looking at using this API in a new community GPS sit i’m building. Will happily credit you if ican use this API - i’ve read the notes about throttling piss-takers!
Drop me a line if you can with any info you think a should know / a graphic or logo if you’d like me to use one on the site and anything else you think may be relevant.
Many thanks
Dave geo@davejavu.co.uk
a work on process » Extending acts_as_geocodable said,
March 11, 2007 @ 1:12 pm
[…] After writing my review of acts_as_geocodable/graticule earlier in the week, I decided to go searching for geocoding services that might offer data for addresses outside of North America. One that I came across is at Local Search Maps. There’s an introductory blog entry here. […]
Google Maps API UK Postcode Geocoding at Andrew Sellick said,
March 16, 2007 @ 4:56 am
[…] Having crawled the internet for a good while a came across the following article Emad Fanous. This article details an API that has been developed to return geocoded addresses, postcodes etc. […]
Ali said,
March 18, 2007 @ 3:30 pm
me again… works without &city=London — thanks emad for this excellent service
Jon said,
April 13, 2007 @ 2:35 am
This might not be the right place but it looks like someone might know an answer.
I have a co-ordinate, 51°32.350711N, 003°08.165039W - anyone know how I can geocode that so that i can use it in Google Maps?
cheers
Duncan Robertson said,
August 28, 2007 @ 7:37 am
I’d just like to say that Emad’s Geocoder service is fantastic and he is prompt and generous with any help he can give. The world would be a nicer place with more guys like him. Thanks again for the help you gave me Emad!
Oliver Beattie said,
October 20, 2007 @ 1:26 pm
I just wanted to leave a quick note to say that I could never thank you enough for such a fantastic service as this. Thank you so much!
Tom said,
January 10, 2008 @ 2:14 am
Anyone know of a utility similar to this(or this one) that we can use without having to pay Google $10,000 a year? and not break their T&C’s
Cheers
Tom
jason said,
April 25, 2008 @ 6:56 am
Does anyone know of Geocoding based on an IP Address free web service in .NET
I want to use it on my site http://www.prop2go.com to help out with localizing the application.
Steven Gruner said,
June 13, 2008 @ 8:22 pm
Looking for the code to this so that I can use it on my server. Tried to run from the links on the pages and nothing spits back. It’s the solution to my page generation problem. I was surprised that there was an actual example of what I was looking for.