栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Google Map Android API V2中两个位置之间的旅行时间

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Google Map Android API V2中两个位置之间的旅行时间

Google Directions JSON Response在“ LEGS”数组中有一个名为Distance和Duration的对象,如下所示:

"legs": [     {         "distance": {  "text": "0.3 km",   "value": 263         },          "duration": {  "text": "1 min",   "value": 52         },       ....... //omitted value        ]

因此,您可以尝试将距离和持续时间(如果需要)解析到您的应用中。也许像这样:

JSonArray legs = jobject.getString("legs");for (int i = 0; i < legs.length(); i++)    {        JSonObject legsObject = legs.getJSonObject(i);        JSonObject distanceObject = legsObject.getString("distance");        String distanceText = distanceObject.getString("text");        String distancevalue = String.valueOf(distanceObject.getString("value"));        //do anything else    }

哦,把腿数组解析放在ArrayTempatMakan解析中。我可以使用Jackson
JSON解析器获取距离和持续时间,因此您应该能够使用org.JSON解析器来实现。

祝你好运^^

编辑:

In this

getDirection (JSonObject jObj)
method You successfully retrieve
objLegs
here, you need to get the Distance and Duration within
objLegs

    JSonObject objRoute = jObj.getJSonArray(TAG_ROUTES).getJSonObject(0);    JSonObject objLegs = objRoute.getJSonArray(TAG_LEGS).getJSonObject(0);    JSonArray arraySteps = objLegs.getJSonArray(TAG_STEPS);

I think you should add this below

objLegs
:

JSonObject objDistance = objLegs.getJSonObject("distance");JSonObject objDuration = objLegs.getJSonObject("duration");String text_distance = objDistance.getString("text");Log.d("Distance", text_distance); //adds an entry to the logCat, Check whether the value of Distance is successfully taken.String text_duration = objDuration.getString("text");Log.d("Duration", text_duration); //adds an entry to the logCat, Check whether the value of Distance is successfully taken.

There, I believe you should be able to grab the value, after that, you can
just add the value into your list result.

If you’re still unable to insert distance and duration, please include the
TempatMakan class on your post.

EDIT 2 :

Declare distance and duration as string inside your TempatMakan.Java :

private String durasi;private String jarak;

inside your constructor :

public TempatMakan(int id, String nama, String alamat, String jarak, String durasi, double lat, double lng){    super();    this.id = id;    this.nama = nama;    this.alamat = alamat;    this.lat = lat;    this.lng = lng;    this.jarak = jarak;    this.durasi = durasi;}

then declare the respective getters and setters for

jarak
and
durasi
.

Inside your

JSONHelper.java
, the
getTempatMakanAll
method, add these :

for (int i = 0; i < arrayTempatMakan.length(); i++)        { JSonObject jobject = arrayTempatMakan.getJSonObject(i); JSonObject objRoute = jobject.getJSonArray(TAG_ROUTES).getJSonObject(0); JSonObject objLegs = objRoute.getJSonArray(TAG_LEGS).getJSonObject(0); JSonObject objDistance = objLegs.getJSonObject("distance"); JSonObject objDuration = objLegs.getJSonObject("duration"); Log.d("log", "muter ke " + i); listTempatMakan.add( new TempatMakan(         jobject.getInt(TAG_ID),         jobject.getString(TAG_NAMA),         jobject.getString(TAG_ALAMAT),         objDistance.getString("text"),//jarak         objDuration.getString("text"),//durasi         jobject.getDouble(TAG_LAT),         jobject.getDouble(TAG_LNG)));        }

after that, just modify your listview adapter to display those values.

Good Luck, and Sorry, I can’t give you another pre or modify your project,
you would have to figure out yourself :)

P.S : Skripsi or Tugas Kuliah?



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/485608.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号