Android使用网络获取定位的方法使用网络获取定位的方法
主要为大家详细介绍了Android使用网络获取定位的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一
下
本文实例为大家分享了Android使用网络获取定位的具体代码,供大家参考,具体内容如下
目标效果:目标效果:
程序运行弹出权限选择,选择运行网络定位后会查询位置,然后在TextView上显示当前国家和城市。
1.activity_main.xml页面定义TextView显示城市名。
activity_main.xml页面:
<RelativeLayout 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="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="正在定位。。。" />
</RelativeLayout>
2.新建Common.java页面,设置公共常量。
Common.java页面:
package com.sc.demo.common;
/**
* 公共常量
* @author wxy
*
*/
public class Common {
public static final String LOCATION = "location";
public static final String LOCATION_ACTION = "locationAction";
}
3.新建LocationSvc.java页面作为服务进行定位。
评论0