File Exchange

image thumbnail

GeoCode

version 1.2.0.0 (2.83 KB) by Stuart Layton
Lookup the latitude and longitude of an address using different geocoding services

11 Downloads

Updated 21 Aug 2012

View Version History

View License

Easily convert a street address into latitude and longitude using one of 3 popular web-based geocoding services (Google Maps, Yahoo Place Finder, and OpenStreetMaps).

Additionally this file works with the newer APIs, that longer require the an API Key or AppId.

Cite As

Stuart Layton (2021). GeoCode (https://www.mathworks.com/matlabcentral/fileexchange/37860-geocode), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (12)

Maram Nour Kasraoui

Hi @Phil
I tried your code but it seems that the characters that you're searching for are not constant('%2C' and '&amp' are not included in my docNode).
Can you please tell me what they exactly mean so I can search for them in my docNode.
Thanks

Phil Harrell

my own attempt at this since this code is giving me errors:

Street_Name = "";
City = "" ;
Zipcode = "";
Address = sprintf('%s %s %s',Street_Name,City,Zipcode);
address = regexprep(Address, ' ', '+');

SERVER_URL = 'https://www.google.com/maps';
queryUrl = sprintf('%s/place/%s',SERVER_URL, address);
queryUrl = regexprep(queryUrl, 'https', 'http');

docNode = webread(queryUrl);
location1 = strfind(docNode,'center');
location2 = strfind(docNode,'%2C');
Coor1 = docNode(location1(1)+7:location2(1)-1)
location3 = strfind(docNode,'&amp');
Coor2 = docNode(location2(1)+3:location3(1)-1)

Coor1 = str2double(sprintf("%.6s",Coor1))
Coor2 = str2double(sprintf("%.6s",Coor2))

let me know if it works for you

Johannes Berndt

Thanks! It works, if you change the SERVER_URL ='http://www...' into: SERVER_URL ='https://www...' .

Israr Bin M Ibrahim

Michael Monaldi

Closest i got was changing lines 48 and 49 to the following:
SERVER_URL = 'http://www.google.com/maps';
queryUrl = sprintf('%s/place/%s',SERVER_URL, address);
but it still does not work...

Ruben Damanik

i have the same error like Jean and Pouyan...anybody can help ?

Jean-Marc Bonello

Anyone have fix for:
Error using geoCode (line 80)
Error, could not reach http://maps.google.com, is it a valid URL?

Rohith

Ingrid

I get the same error as Pouyan, I guess maybe the address has changed since the code is quit old?

Pouyan

I see this error when I try to run the code:

Error using geoCode (line 80)
Error, could not reach http://maps.google.com, is it a valid URL?

Mazin

When I give the function an address it says "No data received from server! Received code:610"

mal flower

This code runs great, but when I check the output from the osm option on another map, the lat / long are way off. Any ideas why?

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!