導航:首頁 > 操作系統 > android獲取gps數據

android獲取gps數據

發布時間:2022-09-14 18:23:12

❶ 請教android中如何調用GPS數據

內置的GPS的信息?

android.location.GpsStatus;
android.location.Location;
android.location.LocationListener;
android.location.LocationManager;

注冊GPS Listener,然後就可以取到了。

❷ android怎樣獲得gps信息

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

private void getLocation()
{
// 獲取位置管理服務
LocationManager locationManager;
String serviceName = Context.LOCATION_SERVICE;
locationManager = (LocationManager) this.getSystemService(serviceName);
// 查找到服務信息
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE); // 高精度
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW); // 低功耗

String provider = locationManager.getBestProvider(criteria, true); // 獲取GPS信息
Location location = locationManager.getLastKnownLocation(provider); // 通過GPS獲取位置
updateToNewLocation(location);
// 設置監聽器,自動更新的最小時間為間隔N秒(1秒為1*1000,這樣寫主要為了方便)或最小位移變化超過N米
locationManager.requestLocationUpdates(provider, 100 * 1000, 500,
locationListener); }

private void updateToNewLocation(Location location) {

TextView tv1;
tv1 = (TextView) this.findViewById(R.id.tv1);
if (location != null) {
double latitude = location.getLatitude();
double longitude= location.getLongitude();
tv1.setText("維度:" + latitude+ "\n經度" + longitude);
} else {
tv1.setText("無法獲取地理信息");
}

}
網路地圖API調用地址:http://api.map..com/geocoder?output=json&location=緯度,經度&key=APP_KEY
谷歌地圖服務API調用地址:http://maps.google.com/maps/api/geocode/json?latlng= 緯度,經度 &language=zh-CN&sensor=true
可以設置返回數據格式,JSON或者XML。

❸ 如何用安卓手機讀取藍牙GPS模塊或記錄儀中的軌跡數據

androidMTK現在可以讀取GPS模塊數據為kml/gpx格式,然後也可以通過藍牙在手機之間傳遞。

❹ 如何獲取安卓手機里的GPS數據和感測器數據

網上有很多的demo 一搜一大把 多看看API 還是說下吧 GPS大概的數據獲取有getAccuracy()、getAltitude()、getBearing()、getLatitude()、getLongitude()、getSpeed()等這么幾個

❺ mqtt 怎麼實現android以後台service的方式獲取gps數據,並定時發送到伺服器

1 從Service繼承一個類。
2 創建startService()方法。
3 創建endService()方法 重載onCreate方法和onDestroy方法,並在這兩個方法裡面來調用startService以及endService。
4 在startService中,通過getSystemService方法獲取Context.LOCATION_SERVICE。
5 基於LocationListener實現一個新類。默認將重載四個方法onLocationChanged、onProviderDisabled、onProviderEnabled、onStatusChanged。對於onLocationChanged方法是我們更新最新的GPS數據的方法。一般我們的操作都只需要在這里進行處理。
6 調用LocationManager的requestLocationUpdates方法,來定期觸發獲取GPS數據即可。在onLocationChanged函數裡面可以實現我們對得到的經緯度的最終操作。
7 最後在我們的Activity裡面通過按鈕來啟動Service,停止Service。
示意代碼如下:
package com.offbye.gpsservice;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
public class GPSService extends Service {
// 2000ms
private static final long minTime = 2000;
// 最小變更距離10m
private static final float minDistance = 10;
String tag = this.toString();
private LocationManager locationManager;
private LocationListener locationListener;
private final IBinder mBinder = new GPSServiceBinder();
public void startService() {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new GPSServiceListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime, minDistance,
locationListener);
}
public void endService() {
if (locationManager != null && locationListener != null) {
locationManager.removeUpdates(locationListener);
}
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return mBinder;
}

❻ Android 怎樣穩定的獲取原生GPS數據

Android 實現穩定獲取原生GPS數據

LocationManager類的對象獲取由系統提供

  1. 為一個LocationManager對象建立一個對象引用

    ❼ android 如何去獲取手機Gps的信號強度

    首先,進入設置選項,在主屏界面中按下Android手機Menu鍵,在彈出的進階菜單中選擇最後一項「Settings」;
    將滑動條拖動至最下方,點擊「About Phone」分類;
    選擇第二項「Status」分類;
    這時,就能夠看到「Signal Strength」選項,前面的-xx(這是一個負數數字)dBm則是手機信號強度。一般「0」—「-50」之間都是一個非常不錯的信號強度,而數值越小則代表著信號越差。

    ❽ Android 怎樣穩定的獲取原生GPS數據

    定位了就有經緯度,沒定位,則一直閃的;
    一般是4個星的時候 會定位。
    所以可以根據是否獲取有效的經緯度信息來判斷是否定位。

    衛星的個數 sv_status也是可以通過API獲取的。LOCATION類
    給你一段我的代碼,看看就知道了。

    locationManager.addGpsStatusListener(statusListener);//偵聽GPS狀態

    private GpsStatus.Listener statusListener = new GpsStatus.Listener()

    {

    public void onGpsStatusChanged(int event)

    {

    // TODO Auto-generated method stub

    GpsStatus gpsStatus= locationManager.getGpsStatus(null);

    Log.v(TAG,"GPS status listener ");

    //Utils.DisplayToastShort(GPSService.this, "GPS status listener ");

    switch(event)

    {

    case GpsStatus.GPS_EVENT_FIRST_FIX:{

    //第一次定位時間UTC gps可用

    //Log.v(TAG,"GPS is usable");

    int i=gpsStatus.getTimeToFirstFix();

    Utils.DisplayToastShort(GPSService.this, "GPS 第一次可用 "+i);

    Utils.setGPSStatus(Utils.GPS_STATUS.START);

    break;

    }

    case GpsStatus.GPS_EVENT_SATELLITE_STATUS:{//周期的報告衛星狀態

    //得到所有收到的衛星的信息,包括 衛星的高度角、方位角、信噪比、和偽隨機號(及衛星編號)

    Iterable<GpsSatellite> allSatellites;

    allSatellites = gpsStatus.getSatellites();

    Iterator<GpsSatellite>iterator = allSatellites.iterator();

    int numOfSatellites = 0;

    int maxSatellites=gpsStatus.getMaxSatellites();

    while(iterator.hasNext() && numOfSatellites<maxSatellites){

    numOfSatellites++;

    iterator.next();

    }

    Log.v(TAG,"GPS is **unusable** "+ numOfSatellites +" "+ maxSatellites);

    if( numOfSatellites < 3){

    // Utils.DisplayToastShort(GPSService.this, "***衛星少於3顆***");

    Utils.setGPSStatus(Utils.GPS_STATUS.STOP);

    } else if(numOfSatellites > 7){

    Utils.setGPSStatus(Utils.GPS_STATUS.START);

    }

    break;

    }

    case GpsStatus.GPS_EVENT_STARTED:{

    //Utils.DisplayToastShort(GPSService.this, "GPS start Event");

    break;

    }

    case GpsStatus.GPS_EVENT_STOPPED:{

    //Utils.DisplayToastShort(GPSService.this, "GPS **stop*** Event");

    Utils.setGPSStatus(Utils.GPS_STATUS.STOP);

    break;

    }

    default :

    break;

    }

    }

    };

閱讀全文

與android獲取gps數據相關的資料

熱點內容
資料庫查詢系統源碼 瀏覽:621
php5314 瀏覽:361
完美國際安裝到哪個文件夾 瀏覽:672
什麼app可以掃一掃做題 瀏覽:542
程序員編碼論壇 瀏覽:928
淘點是什麼app 瀏覽:662
中國高等植物pdf 瀏覽:456
51單片機時間 瀏覽:185
後台如何獲取伺服器ip 瀏覽:269
單片機流水燈程序c語言 瀏覽:237
程序員第二職業掙錢 瀏覽:242
運行里怎麼輸入伺服器路徑 瀏覽:844
pythonstepwise 瀏覽:513
劉一男詞彙速記指南pdf 瀏覽:67
php認證級別 瀏覽:372
方舟編譯啥時候推送 瀏覽:1013
php手機驗證碼生成 瀏覽:678
哲學思維pdf 瀏覽:19
凌達壓縮機有限公司招聘 瀏覽:537
weblogic命令部署 瀏覽:40