关于百度定位sdk的使用 参考官方文档 https://lbsyun.baidu.com/index.php?title=android-locsdk
JSON 解析 参考了 https://blog.youkuaiyun.com/double2hao/article/details/68482900
使用的 天气接口 http://wthrcdn.etouch.cn/weather_mini?city=北京
demo下载:https://download.youkuaiyun.com/download/weixin_42447313/10483975
实现后的效果
布局代码
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.yazz.yaweather.MainActivity"> <TextView android:id="@+id/location_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:textSize="16dp" /> <EditText android:id="@+id/et1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_below="@+id/location_view" android:hint="请输入城市名称:" /> <RelativeLayout android:id="@+id/rl1" android:layout_width="match_parent" android:layout_height="100dp" android:layout_below="@id/et1" android:layout_marginTop="20dp"> <TextView android:id="@+id/weather_view" android:layout_width="192dp" android:layout_height="match_parent" android:gravity="center" android:textSize="16dp" /> <ImageView android:id="@+id/iv1"