Skip to content

Instantly share code, notes, and snippets.

@rajtrivedi2001
Forked from stormxuwz/Google API.m
Created December 29, 2015 12:32
Show Gist options
  • Save rajtrivedi2001/29a9060cb69773cd5414 to your computer and use it in GitHub Desktop.
Save rajtrivedi2001/29a9060cb69773cd5414 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
@tangshuo60
Copy link

what's the parse_jason function?

@Tala22
Copy link

Tala22 commented Aug 20, 2017

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