function wakimapia(lat,lon,zoom)
% WAKIMAPIA A tool to quickly locate the wakimapia to the place specified by latitude and longitude degrees.
%
% Wakimapia is a new interactive map website. However, to navigate to the place you
% are interested is time consumming. This small tool help you to quicky locate the
% wakimapia to the place specified by latitude and longitude degrees.
%
% Usage: wakimapia(lat,long,zoom)
% lat: the latitude degree
% long: the longitude degree
% zoom: zoom level (1 ~ 20), default zoom=17.
%
% Accepted format for lat and long:
% 1. double, e.g. lat=52.073918, long=-1.762439
% 2. string, e.e. lat='N52:04:26', long='W1:45:45'
% 3. cell produced by ukpostcode2latlong
%
% Example 1: use ukpostcode2latlong to get lat and long in cells
% [lat,long]=ukpostcode2latlong('MK430AL');
% wakimapia(lat,long,20);
%
% Example 2: lat and long in double
% wakimapia(52.073918,-0.628756,20);
%
% Example 3: lat and long in string
% wakimapia('N52:04:26','W0:37:44',20);
%
% By Yi Cao at Cranfield University on 26 January 2008
%
%Input check
error(nargchk(2,3,nargin));
if ~isnumeric(lat) % convert lat and long if necessary
[lat,lon]=convert(lat,lon);
if ~isnumeric(lat)
error('Wrong format of Lat and Long used.')
end
end
if nargin<3 % default zoom level
zoom=17;
end
% the url address
url=sprintf('http://www.wikimapia.org/#lat=%f&lon=%f&z=%i&l=0&m=a&v=2',lat,lon,zoom);
% get the web page
web(url)
function [lat,long]=convert(lat,long)
if iscell(lat) % convert cell to string
lat=lat{1};
long=long{1};
end
if ischar(lat) % convert string to double
lat1=str2double(lat);
long1=str2double(long);
if lat1==lat1 % lat=NaN if lat in degree:minute:second format.
lat=lat1;
long=long1;
return
end
% first consider the case produced by ukpostcode2latlong
lat1=regexp(lat,'\s+(\d+.\d+)|(-\d+.\d+)\s+','tokens');
if numel(lat1)
lat1=str2double(lat1{1});
long1=regexp(long,'\s+(\d+.\d+)|(-\d+.\d+)\s+','tokens');
long1=str2double(long1{1});
if lat1==lat1
lat=lat1;
long=long1;
return
end
end
% finally consider the format in degree:minute:second
lat1=regexp(lat,'\w(\d+):(\d+):(\d+)','tokens');
long1=regexp(long,'\w(\d+):(\d+):(\d+)','tokens');
lat1=str2double(lat1{1}{1})+str2double(lat1{1}{2})/60+str2double(lat1{1}{3})/3600;
if lat(1)~='N'
lat1=-lat1;
end
lat=lat1;
long1=str2double(long1{1}{1})+str2double(long1{1}{2})/60+str2double(long1{1}{3})/3600;
if long(1)~='E'
long1=-long1;
end
long=long1;
end