Skip to content

Instantly share code, notes, and snippets.

@stormxuwz
Created May 26, 2014 04:24
Show Gist options
  • Save stormxuwz/9facbbb934c43240ec60 to your computer and use it in GitHub Desktop.
Save stormxuwz/9facbbb934c43240ec60 to your computer and use it in GitHub Desktop.
Matlab Google Street View and Direction API
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
@wikimetralla3
Copy link

sorry i need the parsecoord function to execute the code. Do you have it ? Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment