導航:首頁 > 操作系統 > 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相關的資料

熱點內容
買電暖壺哪個app便宜 瀏覽:503
洛克王國忘記伺服器了怎麼辦 瀏覽:782
為什麼cf登錄伺服器沒反應 瀏覽:695
伺服器如何獲取文件列表 瀏覽:672
creo五軸編程光碟 瀏覽:14
蘋果app網路驗證在哪裡 瀏覽:14
博科清空命令 瀏覽:384
簡愛英文pdf 瀏覽:376
cnc編程有前途嗎 瀏覽:586
聯想app怎麼聯網 瀏覽:722
linuxftp命令登錄 瀏覽:1000
android獲取圖片縮略圖 瀏覽:646
神戶制鋼螺桿壓縮機 瀏覽:29
差分演化演算法 瀏覽:567
中山市加密軟體 瀏覽:446
mc反編譯源碼 瀏覽:141
企業商城網站源碼 瀏覽:411
shell腳本編程是什麼 瀏覽:762
單片機led閃爍匯編 瀏覽:203
點淘app怎麼沒金蛋了 瀏覽:878