导航:首页 > 操作系统 > androidgetspeed

androidgetspeed

发布时间:2023-04-10 15:12:08

android开发怎么获得手机的gps

第一步,申明权限。(5.0之后权限需要动态申请,具体代码和这个问题无关就不贴出来了)

<!--定位权限-->

<uses-permissionandroid:name="android.permission.ACCESS_FINE_LOCATION"/>

<uses-permissionandroid:name="android.permission.ACCESS_COARSE_LOCATION"/>

第二步通过LocationManager类获取位置信息,下面是一个封装好的工具类

**

*/3/15.

*获取当前位置信息

*/

publicclassMyLocationUtil{

privatestaticStringprovider;

(){

//获取当扰伏前位置信息

//获取定位服务

=(LocationManager)MyApp.getContext().getSystemService(Context.LOCATION_SERVICE);

//获取当前可用的位置控制器

List<String>list=locationManager.getProviders(true);

if(list.contains(locationManager.GPS_PROVIDER)){

//GPS位置控埋薯制器

provider=locationManager.GPS_PROVIDER;//GPS定位

}elseif(list.contains(locationManager.NETWORK_PROVIDER)){

//网络位置控制器

provider=locationManager.NETWORK_PROVIDER;//网络定位

}

if(provider!=null){

if(ActivityCompat.checkSelfPermission(MyApp.getContext(),Manifest.permission.ACCESS_FINE_LOCATION)!=PackageManager.PERMISSION_GRANTED&&ActivityCompat.checkSelfPermission(MyApp.getContext(),Manifest.permission.ACCESS_COARSE_LOCATION)!=PackageManager.PERMISSION_GRANTED){

//TODO:Considercalling

//ActivityCompat#requestPermissions

//,andthenoverriding

//(intrequestCode,String[]permissions,

//int[]grantResults)

//.Seethedocumentation

//forActivityCompat#.

returnnull;

}

LocationlastKnownLocation=locationManager.getLastKnownLocation(provider);

returnlastKnownLocation;

}else{

ToastUtils.makeText("请检查网络或GPS是否打开");

}

returnnull;

}

}

第三步(其实到上一步这个问题已经解决了,这个算扩展吧)将位置信息转换成地址信息。

在高德或者网络地图开发者平台申请访问api许可。将第二步获取到的经纬度信息上传查询对应坐标信息。因为网络和高德用的不是同一个坐标系,查询时仔细看官方API。


直接通过安卓的原生接口获取一个gps的位置意义不是很大。这个数据在一定的坐标系上才有意义。建议去高德的开发平台注册个帐号,弯李者引入sdk来做,地理位置与地理位置解析的概念先了解下吧。


//第一步先获取LocationManager的对象LocationManagerGpsManager=(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);//通过LocationManager的对象来获取到Location的信息。Locationlocation=GpsManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);//Location中经常用到的有以下几种:/*location.getAccuracy();精度location.getAltitude();高度:海拔location.getBearing();导向location.getSpeed();速度location.getLatitude();纬度location.getLongitude();经度location.getTime();UTC时间以毫秒计*/注:需要添加使用权限的哦


⑵ retrofit怎么获得post请求数据javabean

本文将介绍如何通过retrofit库post一串json格式的数据。首先post的json数据格式如下:

{
"Id": "string",
"DeviceId": "string",
"Name": "string",
"SumDistance"洞备: 0,
"RouteNo": "string",
"SumPoints": 0,
"SetupTime": "2016-06-10T13:11:00.766Z",
"UsedTime": 0,
"Points": [
{
"Id": "string",
"RouteNo": "string",
"Name": "string",
"Longitude": "string",
"Latitude": "string",
"Height": 0,
"Distance": 0,
"Yaw": 0,
"Pitch": 0,
"Speed": 0,
"Usedtime"晌卖: 0
}
]
}

通过安装Android studio gsonformat插件,根据上面的json格式自动生成一个Bean类,本文命名为FlyRouteBean,

[java] view plain
package com.example.administrator.retrofitex;
import java.util.List;

import android.os.Parcel;
import android.os.Parcelable;

/**
* Created by Administrator on 2016/6/10.
*/
public class FlyRouteBean{

/**
* Id : string
* DeviceId : string
* Name : string
* SumDistance : 0
* RouteNo : string
* SumPoints : 0
* SetupTime : 2016-05-23T06:20:50.254Z
* UsedTime : 0
* Points : [{"Id":"string","RouteNo":"string","Name":"string","Longitude":"string","Latitude":"string","Height":0,"Distance":0,"Yaw":0,"Pitch":0,"纳谨毁Speed":0,"Usedtime":0}]
*/

public String Id;
public String DeviceId;
public String Name;
public double SumDistance;
public String RouteNo;
public int SumPoints;
public String SetupTime;
public double UsedTime;
/**
* Id : string
* RouteNo : string
* Name : string
* Longitude : string
* Latitude : string
* Height : 0
* Distance : 0
* Yaw : 0
* Pitch : 0
* Speed : 0
* Usedtime : 0
*/

public List<PointsBean> Points;

public String getId() {
return Id;
}

public void setId(String Id) {
this.Id = Id;
}

public String getDeviceId() {
return DeviceId;
}

public void setDeviceId(String DeviceId) {
this.DeviceId = DeviceId;
}

public String getName() {
return Name;
}

public void setName(String Name) {
this.Name = Name;
}

public double getSumDistance() {
return SumDistance;
}

public void setSumDistance(double SumDistance) {
this.SumDistance = SumDistance;
}

public String getRouteNo() {
return RouteNo;
}

public void setRouteNo(String RouteNo) {
this.RouteNo = RouteNo;
}

public int getSumPoints() {
return SumPoints;
}

public void setSumPoints(int SumPoints) {
this.SumPoints = SumPoints;
}

public String getSetupTime() {
return SetupTime;
}

public void setSetupTime(String SetupTime) {
this.SetupTime = SetupTime;
}

public double getUsedTime() {
return UsedTime;
}

public void setUsedTime(double UsedTime) {
this.UsedTime = UsedTime;
}

public List<PointsBean> getPoints() {
return Points;
}

public void setPoints(List<PointsBean> Points) {
this.Points = Points;
}

public static class PointsBean implements Parcelable {
public String Id;
public String RouteNo;
public String Name;
public String Longitude;
public String Latitude;
public double Height;
public double Distance;
public double Yaw;
public double Pitch;
public double Speed;
public double Usedtime;

public String getId() {
return Id;
}

public void setId(String Id) {
this.Id = Id;
}

public String getRouteNo() {
return RouteNo;
}

public void setRouteNo(String RouteNo) {
this.RouteNo = RouteNo;
}

public String getName() {
return Name;
}

public void setName(String Name) {
this.Name = Name;
}

public String getLongitude() {
return Longitude;
}

public void setLongitude(String Longitude) {
this.Longitude = Longitude;
}

public String getLatitude() {
return Latitude;
}

public void setLatitude(String Latitude) {
this.Latitude = Latitude;
}

public double getHeight() {
return Height;
}

public void setHeight(double Height) {
this.Height = Height;
}

public double getDistance() {
return Distance;
}

public void setDistance(double Distance) {
this.Distance = Distance;
}

public double getYaw() {
return Yaw;
}

public void setYaw(double Yaw) {
this.Yaw = Yaw;
}

public double getPitch() {
return Pitch;
}

public void setPitch(double Pitch) {
this.Pitch = Pitch;
}

public double getSpeed() {
return Speed;
}

public void setSpeed(double Speed) {
this.Speed = Speed;
}

public double getUsedtime() {
return Usedtime;
}

public void setUsedtime(double Usedtime) {
this.Usedtime = Usedtime;
}

@Override
public String toString() {
return "PointsBean{" +
"Id='" + Id + '\'' +
", RouteNo='" + RouteNo + '\'' +
", Name='" + Name + '\'' +
", Longitude='" + Longitude + '\'' +
", Latitude='" + Latitude + '\'' +
", Height=" + Height +
", Distance=" + Distance +
", Yaw=" + Yaw +
", Pitch=" + Pitch +
", Speed=" + Speed +
", Usedtime=" + Usedtime +
'}';
}

@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeString(Id);
dest.writeString(RouteNo);
dest.writeString(Name);
dest.writeString(Longitude);
dest.writeString(Latitude);
dest.writeDouble(Height);
dest.writeDouble(Distance);
dest.writeDouble(Yaw);
dest.writeDouble(Pitch);
dest.writeDouble(Speed);
dest.writeDouble(Usedtime);
}
public static final Creator<PointsBean> CREATOR=new Creator<PointsBean>() {

@Override
public PointsBean createFromParcel(Parcel source) {
// TODO Auto-generated method stub
PointsBean pointsBean=new PointsBean();
pointsBean.setId(source.readString());
pointsBean.setRouteNo(source.readString());
pointsBean.setName(source.readString());
pointsBean.setLongitude(source.readString());
pointsBean.setLatitude(source.readString());
pointsBean.setHeight(source.readInt());
pointsBean.setDistance(source.readInt());
pointsBean.setYaw(source.readInt());
pointsBean.setPitch(source.readInt());
pointsBean.setSpeed(source.readInt());
pointsBean.setUsedtime(source.readInt());
return pointsBean;
}

@Override
public PointsBean[] newArray(int size) {
// TODO Auto-generated method stub
return new PointsBean[size];
}

};

@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
}

@Override
public String toString() {
return "FlyRouteBean{" +
"Id='" + Id + '\'' +
", DeviceId='" + DeviceId + '\'' +
", Name='" + Name + '\'' +
", SumDistance=" + SumDistance +
", RouteNo='" + RouteNo + '\'' +
", SumPoints=" + SumPoints +
", SetupTime='" + SetupTime + '\'' +
", UsedTime=" + UsedTime +
", Points=" + Points +
'}';
}

}
然后就来建立接口了,其内容如下:
[java] view plain
public interface PostRoute {
@Headers({"Content-Type: application/json","Accept: application/json"})//需要添加头
@POST("api/FlyRoute/Add")
Call<FlyRouteBean> postFlyRoute(@Body RequestBody route);//传入的参数为RequestBody
}
接下来就是提交数据的了:
[java] view plain
FlyRouteBean flyRouteBean=new FlyRouteBean();
flyRouteBean=initdata(flyRouteBean);//根据Bean类初始化一个需要提交的数据类
Gson gson=new Gson();
String route= gson.toJson(flyRouteBean);//通过Gson将Bean转化为Json字符串形式
[java] view plain
Retrofit retrofit=new Retrofit.Builder()
.baseUrl(URL)
.addConverterFactory( GsonConverterFactory.create())
.build();
PostRoute postRoute=retrofit.create(PostRoute.class);
RequestBody body=RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),route);
Call<FlyRouteBean> call=postRoute.postFlyRoute(body);
call.enqueue(new Callback<FlyRouteBean>() {
@Override
public void onResponse(Call<FlyRouteBean> call, Response<FlyRouteBean> response) {
Log.e("sssss","-----------------------"+response.body().getDeviceId());//这里是用于测试,服务器返回的数据就是提交的数据。
}

@Override
public void onFailure(Call<FlyRouteBean> call, Throwable t) {
Log.e("sssss",t.getMessage());
}
});
需要添加的依赖:
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'

⑶ android studio调用百度SDK进行定位,老返回错误码62,怎么回事

主方法 package demo.demo; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import com..location.LocationClient; import com..location.LocationClientOption; public class MapsActivity extends Activity { public LocationClient mLocationClient = null; private LocationClientOption.LocationMode tempMode = LocationClientOption.LocationMode.Hight_Accuracy; private String tempcoor="gcj02"; private TextView textView1; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.this_one); mLocationClient = ((LocationApplication)getApplication()).mLocationClient; textView1= (TextView) findViewById(R.id.textView1); button= (Button) findViewById(R.id.startLocation); ((LocationApplication)getApplication()).mLocationResult = textView1; button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { InitLocation(); mLocationClient.start(); } }); } private void InitLocation(){ LocationClientOption option = new LocationClientOption(); option.setOpenGps(true); option.setLocationMode(tempMode);//设置定帆备模位模式 option.setCoorType(tempcoor);//返回态缓的定位结果是网络经纬度,默认值gcj02 int span=10000; option.setScanSpan(span); /滚消/设置发起定位请求的间隔时间为5000ms option.setIsNeedAddress(true); mLocationClient.setLocOption(option); } @Override protected void onStop() { mLocationClient.stop(); super.onStop(); } } Localapplition文件: package demo.demo; import com..location.BDLocation; import com..location.BDLocationListener; import com..location.LocationClient; import android.app.Application; import android.app.Service; import android.os.Vibrator; import android.util.Log; import android.widget.TextView; /** * 主Application */ public class LocationApplication extends Application { public LocationClient mLocationClient; public MyLocationListener mMyLocationListener; public TextView mLocationResult,logMsg; public Vibrator mVibrator; @Override public void onCreate() { super.onCreate(); mLocationClient = new LocationClient(this.getApplicationContext()); mMyLocationListener = new MyLocationListener(); mLocationClient.registerLocationListener(mMyLocationListener); mVibrator =(Vibrator)getApplicationContext(). getSystemService(Service.VIBRATOR_SERVICE); } /** * 实现实位回调监听 */ public class MyLocationListener implements BDLocationListener { @Override public void onReceiveLocation(BDLocation location) { //Receive Location StringBuffer sb = new StringBuffer(256); sb.append("time :"); sb.append(location.getTime()); sb.append("nerror code :"); sb.append(location.getLocType()); sb.append("nlatitude :"); sb.append(location.getLatitude()); sb.append("nlontitude :"); sb.append(location.getLongitude()); sb.append("nradius :"); sb.append(location.getRadius()); if (location.getLocType() == BDLocation.TypeGpsLocation){ sb.append("nspeed :"); sb.append(location.getSpeed()); sb.append("nsatellite :"); sb.append(location.getSatelliteNumber()); sb.append("ndirection :"); sb.append("naddr :"); sb.append(location.getAddrStr()); sb.append(location.getDirection()); } else if (location.getLocType() == BDLocation.TypeNetWorkLocation){ sb.append("naddr :"); sb.append(location.getAddrStr()); //运营商信息 sb.append("noperationers :"); sb.append(location.getOperators()); } logMsg(sb.toString()); Log.i("BaiLocationApiDem", sb.toString()); } } /** * 显示请求字符串 * @param str */ public void logMsg(String str) { try { if (mLocationResult != null) mLocationResult.setText(str); } catch (Exception e) { e.printStackTrace(); } } }

⑷ android studio怎么实现字幕自动滚动

这个Android字幕滚动类的自定义功能比较多,可定义当前滚动到结尾时的停顿时间,单位:毫秒,还可设置当前的滚动速度,值越小,速度越快游迹。

主要实现代码如下:

?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

package com.tony.autoscroll;
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ScrollView;
/**
* @author Tony
*/
public class AutoScrollView extends ScrollView {
private final Handler handler = new Handler();
private long ration = 50;
private boolean isScrolled = false;
private int currentIndex = 0;
private long period = 1000;
private int currentY = -1;
private double x;
private double y;
private int type = -1;
/**
* @param context
*/
public AutoScrollView(Context context) {
this(context, null);
}
/**
* @param context
* @param attrs
*/
public AutoScrollView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
/**
* @param context
* @param attrs
* @param defStyle
*/
public AutoScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public boolean onTouchEvent(MotionEvent event) {
int Action = event.getAction();
switch (Action) {
case MotionEvent.ACTION_DOWN:
x=event.getX();
y=event.getY();
if (type == 0) {
setScrolled(false);
}
break;
case MotionEvent.ACTION_MOVE:
double moveY = event.getY() - y;
double moveX = event.getX() - x;
Log.d("神郑并test", "moveY = " + moveY + "丛游 moveX = " + moveX );
if ((moveY>20||moveY<-20) && (moveX < 50 || moveX > -50) && getParent() != null) {
getParent().(true);
}
break;
case MotionEvent.ACTION_UP:
if (type == 0) {
currentIndex = getScrollY();
setScrolled(true);
}
break;
default:
break;
}
return super.onTouchEvent(event);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent p_event)
{
Log.d("test", "onInterceptTouchEvent");
return true;
}
/**
* 判断当前是否为滚动状态
* @return the isScrolled
*/
public boolean isScrolled() {
return isScrolled;
}
/**
* 开启或者关闭自动滚动功能
* @param isScrolled
* true为开启,false为关闭
*/
public void setScrolled(boolean isScrolled) {
this.isScrolled = isScrolled;
autoScroll();
}
/**
* 获取当前滚动到结尾时的停顿时间,单位:毫秒
* @return the period
*/
public long getPeriod() {
return period;
}
/**
* 设置当前滚动到结尾时的停顿时间,单位:毫秒
* @param period
*the period to set
*/
public void setPeriod(long period) {
this.period = period;
}
/**
* 获取当前的滚动速度,单位:毫秒,值越小,速度越快。
* @return the speed
*/
public long getSpeed() {
return ration;
}
/**
* 设置当前的滚动速度,单位:毫秒,值越小,速度越快。
* @param speed
*the ration to set
*/
public void setSpeed(long speed) {
this.ration = speed;
}
public void setType(int type){
this.type = type;
}
private void autoScroll() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
boolean flag = isScrolled;
if (flag) {
//Log.d("test", "currentY = " + currentY + " getScrollY() = "+ getScrollY() );
if (currentY == getScrollY()) {
try {
Thread.sleep(period);
} catch (InterruptedException e) {
e.printStackTrace();
}
currentIndex = 0;
scrollTo(0, 0);
handler.postDelayed(this, period);
} else {
currentY = getScrollY();
handler.postDelayed(this, ration);
currentIndex++;
scrollTo(0, currentIndex * 1);
}
} else {
//currentIndex = 0;
//scrollTo(0, 0);
}
}
}, ration);
}
}

⑸ Android 百度地图API问题

首先你要开蚂神启定位图层
mBaiMap.setMyLocationEnabled(true);


定位成功后设置定位数据
mBaiMap.setMyLocationData(locData);


然后移动地图中心点

centerToLocation(location, 250);

protectedvoidcenterToLocation(BDLocationlocation,intration){
LatLngcenpt=newLatLng(location.getLatitude(),location.getLongitude());
//定义地图状态,地图缩放级别3~19
MapStatusnewMapStatus=new州物贺MapStatus.Builder().target(cenpt).zoom(16).build();
//定义MapStatusUpdate对象,以便描述地图状态将要发生的变化
MapStatusUpdate册派mMapStatusUpdate=MapStatusUpdateFactory.newMapStatus(newMapStatus);
//改变地图状态
mBaiMap.animateMapStatus(mMapStatusUpdate,ration);
}

⑹ android 使用百度api怎么快速定位

在下载页面下载最新的库文件。将liblocSDK2.4.so文件拷贝到libs/armeabi目录下。将locSDK2.4.jar文件拷贝到工程根目录下,并在工程属性->Java Build Path->Libraries中选择“Add JARs”,选定locSDK2.4.jar,确定后返回。这样您就可以在程序中使用网络定位API了。

设置AndroidManifest.xml
为区分2.3版本service,需要将manifest file中的 intent filter声明为com..location.service_v2.4 在application标签中声明service组件

<service android:name="com..location.f" android:enabled="true" android:process=":remote" android:permission="android.permission.BAIDU_LOCATION_SERVICE"> <intent-filter> <action android:name="com..location.service_v2.4"></action> </intent-filter></service>声明使用权限

<permission android:name="android.permission.BAIDU_LOCATION_SERVICE"></permission><uses-permission android:name="android.permission.BAIDU_LOCATION_SERVICE"></uses-permission><uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission><uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission><uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission><uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission><uses-permission android:name="android.permission.READ_LOGS"></uses-permission>import相关类

import com..location.BDLocation;import com..location.BDLocationListener;import com..location.LocationClient;import com..location.LocationClientOption;import com..location.BDNotifyListener;//假如用到位置提醒功能,需要import该类功能类的使用
初始化LocationClient类
此处需要注意:LocationClient类必须在主线程中声明。需要Context类型的参数。

public LocationClient mLocationClient = null;public BDLocationListener myListener = new MyLocationListener(); public void onCreate() { mLocationClient = new LocationClient(this); //声明LocationClient类 mLocationClient.registerLocationListener( myListener ); //注册监听函数}实现BDLocationListener接口
BDLocationListener接口有2个方法需要实现:
1.接收异步返回的定位结果,参数是BDLocation类型参数。
2.接收异步返回的POI查询结果,参数是BDLocation类型参数。

public class MyLocationListenner implements BDLocationListener { @Override public void onReceiveLocation(BDLocation location) { if (location == null) return ; StringBuffer sb = new StringBuffer(256); sb.append("time : "); sb.append(location.getTime()); sb.append("\nerror code : "); sb.append(location.getLocType()); sb.append("\nlatitude : "); sb.append(location.getLatitude()); sb.append("\nlontitude : "); sb.append(location.getLongitude()); sb.append("\nradius : "); sb.append(location.getRadius()); if (location.getLocType() == BDLocation.TypeGpsLocation){ sb.append("\nspeed : "); sb.append(location.getSpeed()); sb.append("\nsatellite : "); sb.append(location.getSatelliteNumber()); } else if (location.getLocType() == BDLocation.TypeNetWorkLocation){ sb.append("\naddr : "); sb.append(location.getAddrStr()); } logMsg(sb.toString()); }public void onReceivePoi(BDLocation poiLocation) { if (poiLocation == null){ return ; } StringBuffer sb = new StringBuffer(256); sb.append("Poi time : "); sb.append(poiLocation.getTime()); sb.append("\nerror code : "); sb.append(poiLocation.getLocType()); sb.append("\nlatitude : "); sb.append(poiLocation.getLatitude()); sb.append("\nlontitude : "); sb.append(poiLocation.getLongitude()); sb.append("\nradius : "); sb.append(poiLocation.getRadius()); if (poiLocation.getLocType() == BDLocation.TypeNetWorkLocation){ sb.append("\naddr : "); sb.append(poiLocation.getAddrStr()); } if(poiLocation.hasPoi()){ sb.append("\nPoi:"); sb.append(poiLocation.getPoi()); }else{ sb.append("noPoi information"); } logMsg(sb.toString()); }}设置参数
设置定位参数包括:定位模式(单次定位,定时定位),返回坐标类型,是否打开GPS等等。eg:

LocationClientOption option = new LocationClientOption();option.setOpenGps(true);option.setAddrType("detail");option.setCoorType("gcj02");option.setScanSpan(5000);option.disableCache(true);//禁止启用缓存定位option.setPoiNumber(5); //最多返回POI个数 option.setPoiDistance(1000); //poi查询距离 option.setPoiExtraInfo(true); //是否需要POI的电话和地址等详细信息 mLocClient.setLocOption(option);发起定位请求
发起定位请求。请求过程是异步的,定位结果在上面的监听函数onReceiveLocation中获取。

if (mLocClient != null && mLocClient.isStarted()) mLocClient.requestLocation();else Log.d("LocSDK_2.0_Demo1", "locClient is null or not started");发起POI查询请求
发起POI查询请求。请求过程是异步的,定位结果在上面的监听函数onReceivePoi中获取。

if (mLocClient != null && mLocClient.isStarted()) mLocClient.requestPoi();位置提醒使用
位置提醒最多提醒3次,3次过后将不再提醒。 假如需要再次提醒,或者要修改提醒点坐标,都可通过函数SetNotifyLocation()来实现。

//位置提醒相关代码mNotifyer = new NotifyLister();mNotifyer.SetNotifyLocation(42.03249652949337,113.3129895882556,3000,"gps");//4个参数代表要位置提醒的点的坐标,具体含义依次为:纬度,经度,距离范围,坐标系类型(gcj02,gps,bd09,bd09ll)mLocationClient.registerNotify(mNotifyer);//注册位置提醒监听事件后,可以通过SetNotifyLocation 来修改位置提醒设置,修改后立刻生效。
//BDNotifyListner实现public class NotifyLister extends BDNotifyListener{ public void onNotify(BDLocation mlocation, float distance){ mVibrator01.vibrate(1000);//振动提醒已到设定位置附近 }}
//取消位置提醒mLocationClient.removeNotifyEvent(mNotifyer);

⑺ 如何删除Android GPS的数据

网上有很多的demo一搜一大把多看看API还是说下吧GPS大概的举碧数据获启裂取有getAccuracy()、getAltitude()、getBearing()、getLatitude()、getLongitude()、getSpeed()等这么几个正旁举查看原帖>>

⑻ Android 如何实现单击百度地图获取单击点经纬度

转载自http://www.open-open.com/lib/view/open1346982366162.html 程序有点过时但是 改改还能用
使用Android自带的LocationManager和Location获取位置的时候,经常会有获取的location为null的情况,并且操作起来也不是很方便,在这个Demo里我使用了网络地图API中的定位SDK,可以一次性获取当前位置经纬度以及详细地址信息,还可以获取周边POI信息,同时可以设定位置通知点,当到达某一位置时,发出通知信息等方式来告知用户。jar包下载以及官方文档请参照:网络定位SDK,前提是需要注册网络开发者账号。
下面来看看定位的基本原理,目前,定位SDK可以通过GPS、基站、Wifi信号进行定位。基本定位流程如下图所示,当应用程序向定位SDK发起定位请求时,定位SDK会根据当前的GPS、基站、Wifi信息生成相对应的定位依据。然后定位SDK会根据定位依据来进行定位。如果需要,定位SDK会向定位服务器发送网络请求。定位服务器会根据请求的定位依据推算出对应的坐标位置,然后根据用户的定制信息,生成定位结果返回给定位SDK。

到官方下载jar文件后添加到工程,工程目录截图如下:

注意要把locSDK_2.4.jar添加到当天工程,右键jar文件-Build path-Add to。。。

上代码
布局文件:

01 <?xml version="1.0" encoding="utf-8"?>
02 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
03 android:layout_width="fill_parent"
04 android:layout_height="fill_parent"
05 android:orientation="vertical" >
06
07 <Button
08 android:id="@+id/btn_start"
09 android:layout_width="fill_parent"
10 android:layout_height="wrap_content"
11 android:layout_marginTop="20dp"
12 android:text="Start"/>
13
14 <TextView
15 android:id="@+id/tv_loc_info"
16 android:layout_width="fill_parent"
17 android:layout_height="wrap_content"
18 android:textSize="18sp" />
19
20 </LinearLayout>

配置文件:

01 <?xml version="1.0" encoding="utf-8"?>
02 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
03 package="com.ericssonlabs"
04 android:versionCode="1"
05 android:versionName="1.0" >
06
07 <uses-sdk android:minSdkVersion="8" />
08
09 <permission android:name="android.permission.BAIDU_LOCATION_SERVICE" >
10 </permission>
11
12 <uses-permission android:name="android.permission.BAIDU_LOCATION_SERVICE" >
13 </uses-permission>
14 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" >
15 </uses-permission>
16 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" >
17 </uses-permission>
18 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" >
19 </uses-permission>
20 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >
21 </uses-permission>
22 <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" >
23 </uses-permission>
24 <uses-permission android:name="android.permission.READ_PHONE_STATE" >
25 </uses-permission>
26 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" >
27 </uses-permission>
28 <uses-permission android:name="android.permission.INTERNET" />
29 <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" >
30 </uses-permission>
31 <uses-permission android:name="android.permission.READ_LOGS" >
32 </uses-permission>
33
34 <application
35 android:icon="@drawable/ic_launcher"
36 android:label="@string/app_name" >
37 <activity
38 android:name=".LocationDemoActivity"
39 android:label="@string/app_name" >
40 <intent-filter>
41 <action android:name="android.intent.action.MAIN" />
42
43 <category android:name="android.intent.category.LAUNCHER" />
44 </intent-filter>
45 </activity>
46
47 <service
48 android:name="com..location.f"
49 android:enabled="true"
50 android:permission="android.permission.BAIDU_LOCATION_SERVICE"
51 android:process=":remote" >
52 <intent-filter>
53 <action android:name="com..location.service_v2.4" />
54 </intent-filter>
55 </service>
56 </application>
57
58 </manifest>

实现代码:

001 public class LocationDemoActivity extends Activity {
002 private TextView locationInfoTextView = null;
003 private Button startButton = null;
004 private LocationClient locationClient = null;
005 private static final int UPDATE_TIME = 5000;
006 private static int LOCATION_COUTNS = 0;
007
008 @Override
009 public void onCreate(Bundle savedInstanceState) {
010 super.onCreate(savedInstanceState);
011 setContentView(R.layout.main);
012
013 locationInfoTextView = (TextView) this.findViewById(R.id.tv_loc_info);
014 startButton = (Button) this.findViewById(R.id.btn_start);
015
016
017 locationClient = new LocationClient(this);
018 //设置定位条件
019 LocationClientOption option = new LocationClientOption();
020 option.setOpenGps(true); //是否打开GPS
021 option.setCoorType("bd09ll"); //设置返回值的坐标类型。
022 option.setPriority(LocationClientOption.NetWorkFirst); //设置定位优先级
023 option.setProdName("LocationDemo"); //设置产品线名称。强烈建议您使用自定义的产品线名称,方便我们以后为您提供更高效准确的定位服务。
024 option.setScanSpan(UPDATE_TIME); //设置定时定位的时间间隔。单位毫秒
025 locationClient.setLocOption(option);
026
027 //注册位置监听器
028 locationClient.registerLocationListener(new BDLocationListener() {
029
030 @Override
031 public void onReceiveLocation(BDLocation location) {
032 // TODO Auto-generated method stub
033 if (location == null) {
034 return;
035 }
036 StringBuffer sb = new StringBuffer(256);
037 sb.append("Time : ");
038 sb.append(location.getTime());
039 sb.append("\nError code : ");
040 sb.append(location.getLocType());
041 sb.append("\nLatitude : ");
042 sb.append(location.getLatitude());
043 sb.append("\nLontitude : ");
044 sb.append(location.getLongitude());
045 sb.append("\nRadius : ");
046 sb.append(location.getRadius());
047 if (location.getLocType() == BDLocation.TypeGpsLocation){
048 sb.append("\nSpeed : ");
049 sb.append(location.getSpeed());
050 sb.append("\nSatellite : ");
051 sb.append(location.getSatelliteNumber());
052 } else if (location.getLocType() == BDLocation.TypeNetWorkLocation){
053 sb.append("\nAddress : ");
054 sb.append(location.getAddrStr());
055 }
056 LOCATION_COUTNS ++;
057 sb.append("\n检查位置更新次数:");
058 sb.append(String.valueOf(LOCATION_COUTNS));
059 locationInfoTextView.setText(sb.toString());
060 }
061
062 @Override
063 public void onReceivePoi(BDLocation location) {
064 }

⑼ Android如何较为精确获取到当前移动速度

android.view.VelocityTracker主要用跟踪触摸屏事件(flinging事件和其腔谨他gestures手势事件)的速率。用addMovement(MotionEvent)函数将Motion event加入到VelocityTracker类实例中.你可以使用getXVelocity() 或getXVelocity()获得横向和竖向的速率到速率时,但是使用它们之前请先调用computeCurrentVelocity(int)来初始化速率的单位 。
主要函数逗毕

Public Methods

void addMovement(MotionEvent event)
Add a user's movement to the tracker.

void clear()
Reset the velocity tracker back to its initial state.

void computeCurrentVelocity(int units, float maxVelocity)
Compute the current velocity based on the points that have been collected.
int unitis表示速率的基本时间单位。unitis值为1的表示是,一毫秒时间单位内运动了多少个像素, unitis值为1000表示一秒(1000毫伍指基秒)时间单位内运动了多少个像素
floatVelocity表示速率的最大值

void computeCurrentVelocity(int units)
Equivalent to invoking computeCurrentVelocity(int, float) with a maximum velocity of Float.MAX_VALUE.

abstract T getNextPoolable()
float getXVelocity()
Retrieve the last computed X velocity.

float getXVelocity(int id)
Retrieve the last computed X velocity.

float getYVelocity(int id)
Retrieve the last computed Y velocity.

float getYVelocity()
Retrieve the last computed Y velocity.

abstract boolean isPooled()
static VelocityTracker obtain()
Retrieve a new VelocityTracker object to watch the velocity of a motion.

void recycle()
Return a VelocityTracker object back to be re-used by others.

abstract void setNextPoolable(T element)
abstract void setPooled(boolean isPooled)
示例:
private VelocityTracker mVelocityTracker;//生命变量
//在onTouchEvent(MotionEvent ev)中
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();//获得VelocityTracker类实例
}
mVelocityTracker.addMovement(ev);//将事件加入到VelocityTracker类实例中
//判断当ev事件是MotionEvent.ACTION_UP时:计算速率
final VelocityTracker velocityTracker = mVelocityTracker;
// 1000 provides pixels per second
velocityTracker.computeCurrentVelocity(1, (float)0.01); //设置maxVelocity值为0.1时,速率大于0.01时,显示的速率都是0.01,速率小于0.01时,显示正常
Log.i("test","velocityTraker"+velocityTracker.getXVelocity());
velocityTracker.computeCurrentVelocity(1000); //设置units的值为1000,意思为一秒时间内运动了多少个像素
Log.i("test","velocityTraker"+velocityTracker.getXVelocity());
大体的使用是这样的:
当你需要跟踪触摸屏事件的速度的时候,使用obtain()方法来获得VelocityTracker类的一个实例对象
在onTouchEvent回调函数中,使用addMovement(MotionEvent)函数将当前的移动事件传递给VelocityTracker对象
使用computeCurrentVelocity (int units)函数来计算当前的速度,使用 getXVelocity ()、 getYVelocity ()函数来获得当前的速度

⑽ android下百度地图的api如何得到速度

很灶宏蚂有可能你定位绝或得到location,不是GPS产生的,而是网络定位产生的。因为前者有可能要1分钟多才能定位,而后者一般在1秒钟隐埋内就能定位。而后者,是没有速度的。
如需判断你的location是否是从GPS得到的,用location.getLocType() == BDLocation.TypeGpsLocation来判断。
请参考网络定位的示例代码:
public class MyLocationListener implements BDLocationListener {

@Override
public void onReceiveLocation(BDLocation location) {
//Receive Location
StringBuffer sb = new StringBuffer(256);
sb.append("time : ");
sb.append(location.getTime());
sb.append("\nerror code : ");
sb.append(location.getLocType());
sb.append("\nlatitude : ");
sb.append(location.getLatitude());
sb.append("\nlontitude : ");
sb.append(location.getLongitude());
sb.append("\nradius : ");
sb.append(location.getRadius());
if (location.getLocType() == BDLocation.TypeGpsLocation){
sb.append("\nspeed : ");
sb.append(location.getSpeed());
sb.append("\nsatellite : ");
sb.append(location.getSatelliteNumber());
sb.append("\ndirection : ");
sb.append("\naddr : ");
sb.append(location.getAddrStr());
sb.append(location.getDirection());
} else if (location.getLocType() == BDLocation.TypeNetWorkLocation){
sb.append("\naddr : ");
sb.append(location.getAddrStr());
//运营商信息
sb.append("\noperationers : ");
sb.append(location.getOperators());
}
logMsg(sb.toString());
Log.i("BaiLocationApiDem", sb.toString());
}

}

阅读全文

与androidgetspeed相关的资料

热点内容
pr怎么压缩文件大小 浏览:859
查看oracle字符集命令 浏览:175
锂电池增加密度 浏览:657
linux用户密码忘记 浏览:240
gb压缩天然气 浏览:633
图片拼接不压缩app 浏览:668
我的世界如何编程 浏览:84
vue反编译代码有问题 浏览:948
linuxshell字符串连接字符串 浏览:51
androidviewpager刷新 浏览:438
python编程计算平均分 浏览:678
加密数字货币市值查询 浏览:692
时尚商圈app怎么样 浏览:584
stacklesspython教程 浏览:138
用命令行禁用135端口 浏览:212
linux防火墙编程 浏览:627
pdf阅读器删除 浏览:979
考研人如何缓解压力 浏览:822
买电暖壶哪个app便宜 浏览:505
洛克王国忘记服务器了怎么办 浏览:782