-
-
Save rajtrivedi2001/29a9060cb69773cd5414 to your computer and use it in GitHub Desktop.
Matlab Google Street View and Direction API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
origin='Madison,Chicago,IL'; | |
destination='N+Michigan+Ave,Chicago,IL'; | |
url1=['https://maps.googleapis.com/maps/api/directions/json?origin=' origin '&destination=' destination '&sensor=false&key= XXXX&departure_time=1343641500&mode=driving']; | |
direction=urlread(url1); | |
d=parse_json(direction); | |
steps=d{1}.routes{1}.legs{1}.steps; | |
[startpoints,endpoints]=cellfun(@parsecoord,steps); | |
for i=1:numel(steps) % For each step, find the midpoint and save the street view image | |
sp=startpoints(i); | |
spLat=sp.lat; | |
spLong=sp.lng; | |
ep=endpoints(i); | |
epLat=ep.lat; | |
epLong=ep.lng; | |
mpLat=(spLat+epLat)/2; | |
mpLong=(spLong+epLong)/2; | |
%directiondegree=azimuth(spLat,spLong,epLat,epLong); % calculate the azimuth,i.e. the direction of car | |
directiondegree=0; | |
roadLat=mpLat; | |
roadLong=mpLong; | |
heading=directiondegree; | |
url=['http://maps.googleapis.com/maps/api/streetview?size=640x640&location=' num2str(roadLat) ',' num2str(roadLong) '&sensor=True&key=XXXX&heading=' num2str(heading)]; | |
filename=[num2str(i) '_test.jpg']; | |
urlwrite(url,filename); | |
%b=imread(filename); | |
%image(b) | |
end | |
I am receiving following error:
Error using urlreadwrite (line 98)
Error downloading URL. Your network connection may be down or your proxy settings improperly configured.
Error in urlwrite (line 38)
[f,status] = urlreadwrite(mfilename,catchErrors,url,filename,varargin{:});
Error in Untitled (line 37)
urlwrite(url,filename);
Solved by changing API key
sorry, can you upload the whole code? the error is that I do not define 'd=parse_json(direction)'. thank you
what's the parse_jason function?
Could you please guide me to change this code to use Google Translation API , to translate text using that API during MATLAB?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create a new file with following code:
and save it with name 'parsecoord.m' in bin directory
function [startpoints,endpoints] = parsecoord(input)
%parsecoord parse the cooordinate
startpoints = input.start_location;
endpoints =input.start_location;
end