基于图结构实现地铁乘坐线路查询 (2)

具体详情查看flask官方中文文档

# encoding=utf-8 from flask import Flask, request from stationController import getShort from stationController import getInfoStation import json app = Flask(__name__) @app.route('/getStationInfo', methods=['GET']) def getStationInfo(): num = request.args["num"] num = int(num) data, stationlist = getInfoStation() if not num: result = { "code": 500, "msg": "the service make a mistake -.-" } else: strmsg = data[num] print(strmsg) result = { "code": 0, "msg": strmsg } return json.dumps(result) @app.route('/getShortestPath', methods=['GET']) def getShortestPath(): start = request.args['start'] end = request.args['end'] data, stationlist = getInfoStation() print(start not in stationlist.keys() and end not in stationlist.keys) if (not start or not end) or (start not in stationlist.keys() or end not in stationlist.keys()): result = { "code": 501, "msg": "please input the correct start and end station -.-" } else: stationnum, strmsg = getShort(start, end) result = { "code": 0, "msg": strmsg, "stationnum": stationnum } return json.dumps(result) if __name__ == '__main__': app.run(host="0.0.0.0", port=80)

flask具体demo已经部署在服务器上,返回信息,请求方式等具体请查看接口文档:传送门

安卓部分

编译器使用AS进行开发

使用友好的流线式布局进行开发

布局代码如下:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="10dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="30dp" android:orientation="vertical" tools:context=".MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="请选择站点线路起点线" /> <LinearLayout android:layout_width="match_parent" android:layout_height="141dp" android:layout_gravity="center" android:orientation="vertical"> <Spinner android:id="@+id/spinner1" android:layout_width="match_parent" android:layout_height="50dp" /> <Spinner android:id="@+id/spinner2" android:layout_width="match_parent" android:layout_height="50dp" android:layout_marginTop="20dp" /> </LinearLayout> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="请选择站点线路终点线" /> <LinearLayout android:layout_width="match_parent" android:layout_height="141dp" android:layout_gravity="center" android:orientation="vertical"> <Spinner android:id="@+id/spinner3" android:layout_width="match_parent" android:layout_height="50dp" /> <Spinner android:id="@+id/spinner4" android:layout_width="match_parent" android:layout_height="50dp" android:layout_marginTop="20dp" /> </LinearLayout> <Button android:id="@+id/searchButton" android:layout_width="match_parent" android:layout_height="40dp" android:text="搜索最短路线"> </Button> <TextView android:id="@+id/showShortestPath" android:layout_width="match_parent" android:layout_height="match_parent" android:text=""> </TextView> </LinearLayout>

对与spinner(下拉框的集联操作使用xml进行了储存)

当选中相应的station值时进行选择第二个spinner中的应该显示的值

格式如下

<?xml version="1.0" encoding="utf-8"?> <resources> <string-array> <item>-站点线路-</item> <item>1</item> <item>2</item> <item>3</item> <item>5</item> <item>6</item> <item>9</item> </string-array> <string-array> <item>-站点-</item> <item>刘园</item> <item>西横堤</item> <item>果酒厂</item> <item>本溪路</item> <item>勤俭道</item> <item>洪湖里</item> <item>西站</item> <item>西北角</item> <item>西南角</item> <item>二纬路</item> <item>海光寺</item> <item>鞍山道</item> <item>营口道</item> <item>小白楼</item> <item>下瓦房</item> <item>南楼</item> <item>土城</item> <item>陈塘庄</item> <item>复兴门</item> <item>华山里</item> <item>财经大学</item> <item>双林</item> <item>李楼</item> </string-array> ...... </resources>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzjswg.html