필터 지우기
필터 지우기

How to save numerical data into excel from Google maps API run in MATLAB.

조회 수: 5 (최근 30일)
Hi, I am running a script in the google maps API from MATLAB and receive following information. How do I save the distance and duration in an excel file?
The code is: str='https://maps.googleapis.com/maps/api/distancematrix/json?origins=nottingham&destinations=london|manchester|liverpool&key=API key';
result = urlread(str)
This is the result:
{
"destination_addresses" : [ "London, UK", "Manchester, UK", "Liverpool, Merseyside, UK" ],
"origin_addresses" : [ "Nottingham, Nottingham, UK" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "205 km",
"value" : 204693
},
"duration" : {
"text" : "2 hours 43 mins",
"value" : 9809
},
"status" : "OK"
},
{
"distance" : {
"text" : "160 km",
"value" : 160238
},
"duration" : {
"text" : "2 hours 7 mins",
"value" : 7633
},
"status" : "OK"
},
{
"distance" : {
"text" : "179 km",
"value" : 179222
},
"duration" : {
"text" : "2 hours 13 mins",
"value" : 7962
},
"status" : "OK"
}
]
}
],
"status" : "OK"
  댓글 수: 2
Walter Roberson
Walter Roberson 2016년 1월 7일
It looks to me as if this is missing a "}" at the end.
Kingshuk Islam
Kingshuk Islam 2016년 1월 13일
Hello Walter,
I am not entirely sure I understand. This is the answer shown to me by matlab. I want to save the "km" and "mins" data in excel from here.

댓글을 달려면 로그인하십시오.

채택된 답변

Robert Snoeberger
Robert Snoeberger 2016년 1월 15일
Use webread instead of urlread. It will parse the JSON response for you. Then, you can gather the distance and duration data that you want and create a table. Once you have a table, you can write the table to an Excel file.
Example
>> url = ''https://maps.googleapis.com/maps/api/distancematrix/json?origins=nottingham&destinations=london|manchester|liverpool&key=API key';
>> result = webread(url);
>> % gather distance and duration data from the result and create a table
>> address = result.destination_addresses;
>> distances = [result.rows.elements.distance];
>> distance = {distances.text}';
>> durations = [result.rows.elements.duration];
>> duration = {durations.text}';
>> t = table(address, distance, duration)
t =
address distance duration
___________________________ ________ _________________
'London, UK' '205 km' '2 hours 43 mins'
'Manchester, UK' '160 km' '2 hours 7 mins'
'Liverpool, Merseyside, UK' '179 km' '2 hours 13 mins'
>>
>> % write table to Excel file
>> writetable(t, 'dist_and_dur.xls');
  댓글 수: 5
dimitrios chatziioannides
dimitrios chatziioannides 2017년 2월 22일
if i have a lot of points (coordinates/cities) in an excel file and i want to find the distance of each other, how i suppose to do that? can you give a code for that case?
Manivannan chandrasekaran
Manivannan chandrasekaran 2017년 12월 30일
편집: Manivannan chandrasekaran 2017년 12월 30일
Thanks its working
please tell me how to tabulate more than one city as origin

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by