本文整理匯總了Java中android.location.GpsSatellite.getSnr方法的典型用法代碼示例。如果您正苦於以下問題:Java GpsSatellite.getSnr方法的具體用法?Java GpsSatellite.getSnr怎麽用?Java GpsSatellite.getSnr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.location.GpsSatellite
的用法示例。
在下文中一共展示了GpsSatellite.getSnr方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateStatus
import android.location.GpsSatellite; //導入方法依賴的package包/類
private void updateStatus(GpsStatus status) {
setStarted(true);
Iterator<GpsSatellite> satellites = status.getSatellites().iterator();
if (mPrns == null) {
int length = status.getMaxSatellites();
mPrns = new int[length];
mSnrs = new float[length];
mSvElevations = new float[length];
mSvAzimuths = new float[length];
}
mSvCount = 0;
while (satellites.hasNext()) {
GpsSatellite satellite = satellites.next();
int prn = satellite.getPrn();
mPrns[mSvCount] = prn;
mSnrs[mSvCount] = satellite.getSnr();
mSvElevations[mSvCount] = satellite.getElevation();
mSvAzimuths[mSvCount] = satellite.getAzimuth();
mSvCount++;
}
mAdapter.notifyDataSetChanged();
}
示例2: setSats
import android.location.GpsSatellite; //導入方法依賴的package包/類
public void setSats(GpsStatus status) {
Iterator<GpsSatellite> satellites = status.getSatellites().iterator();
if (mSnrs == null) {
int length = status.getMaxSatellites();
mSnrs = new float[length];
mElevs = new float[length];
mAzims = new float[length];
}
mSvCount = 0;
while (satellites.hasNext()) {
GpsSatellite satellite = satellites.next();
mSnrs[mSvCount] = satellite.getSnr();
mElevs[mSvCount] = satellite.getElevation();
mAzims[mSvCount] = satellite.getAzimuth();
mSvCount++;
}
mStarted = true;
invalidate();
}
示例3: onGpsStatusChanged
import android.location.GpsSatellite; //導入方法依賴的package包/類
public void onGpsStatusChanged(int event) {
switch (event) {
// 第一次定位
case GpsStatus.GPS_EVENT_FIRST_FIX:
LogUtil.d("第一次定位");
break;
// 衛星狀態改變
case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
// LogUtil.d("衛星狀態改變");
// 獲取當前狀態
GpsStatus gpsStatus = lm.getGpsStatus(null);
// 獲取衛星顆數的默認最大值
int maxSatellites = gpsStatus.getMaxSatellites();
// 創建一個迭代器保存所有衛星
Iterator<GpsSatellite> iters = gpsStatus.getSatellites()
.iterator();
int count = 0;
while (iters.hasNext() && count <= maxSatellites) {
GpsSatellite s = iters.next();
//返回衛星的信噪比
float snr = s.getSnr();
if (snr > 0) {
count++;
}
}
//在gps衛星信號數量少於4個的情況下 且定位模式為設備模式的情況,切換到高精度模式
if (count < 4 && mLocationOption.getLocationMode() == AMapLocationClientOption.AMapLocationMode.Device_Sensors) {
//累加無信號時間
noGpsTime++;
String logStr = "\n搜索到:" + count + "顆有效衛星,沒有gps信號時間" + noGpsTime+"\n";
LogUtil.d(logStr);
//記錄日誌
LogUtil.save(MapService.this, logStr);
// Toast.makeText(MapService.this, "無衛星時間"+noGpsTime, Toast.LENGTH_SHORT).show();
ToastUtil.show(MapService.this, "無衛星時間:" + noGpsTime);
//持續時間10秒以上
if (noGpsTime >= 5) {
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
mLocationOption.setInterval(intervaTime);
mLocationClient.setLocationOption(mLocationOption);
//mLocationClient.startLocation();
noGpsTime = 0;
LogUtil.save(MapService.this, "\n已經持續10秒無衛星信號,切換回高精度模式\n");
Toast.makeText(MapService.this, "當前無法獲取gps信號,轉為高精度定位模式", Toast.LENGTH_SHORT).show();
}
} else {
noGpsTime = 0;
}
// Toast.makeText(MapService.this, "搜索到:" + count + "顆有效衛星", Toast.LENGTH_SHORT).show();
break;
// 定位啟動
case GpsStatus.GPS_EVENT_STARTED:
LogUtil.d("定位啟動");
break;
// 定位結束
case GpsStatus.GPS_EVENT_STOPPED:
LogUtil.d("定位結束");
break;
}
}
示例4: convertNmeaGSV
import android.location.GpsSatellite; //導入方法依賴的package包/類
public static String[] convertNmeaGSV(List<GpsSatellite> satellites) {
StringBuilder localStringBuilder = new StringBuilder();
// all satellite in ephemeris, include InUse, Seen and Not seen.
// but the size will change dynamically.
int seenCount = satellites.size();
if (seenCount <= 0) {
localStringBuilder.append("$GPGSV,1,1,00");
localStringBuilder.append(calcNmeaCrc(localStringBuilder));
return new String[]{localStringBuilder.toString()};
}
int msgRows = (seenCount + 3) / 4;
String[] arrayOfString = new String[msgRows];
//int prn, elevation, azimuth, snr;
for (int i = 0; i < msgRows; i++) {
localStringBuilder.setLength(0);
localStringBuilder.append(String.format(Locale.getDefault(), "$GPGSV,%d,%d,%02d", msgRows, i + 1, seenCount));
for (int j = 0; j < 4; j++) {
if (i * 4 + j >= satellites.size())
break;
GpsSatellite g = satellites.get(i * 4 + j);
//prn = g.getPrn();
//elevation = (int)g.getElevation();
//azimuth = (int)g.getAzimuth();
//snr = (int)g.getSnr();
if ((int) g.getSnr() == 0) {
localStringBuilder.append(String.format(Locale.getDefault(), ",%02d,%02d,%03d,",
g.getPrn(), (int) g.getElevation(), (int) g.getAzimuth()));
} else {
localStringBuilder.append(String.format(Locale.getDefault(), ",%02d,%02d,%03d,%02d",
g.getPrn(), (int) g.getElevation(), (int) g.getAzimuth(), (int) g.getSnr()));
}
}
localStringBuilder.append(calcNmeaCrc(localStringBuilder));
arrayOfString[i] = localStringBuilder.toString();
}
return arrayOfString;
}
示例5: onGpsStatusChanged
import android.location.GpsSatellite; //導入方法依賴的package包/類
public void onGpsStatusChanged(int event) {
switch (event) {
case GpsStatus.GPS_EVENT_FIRST_FIX:
Log.i(TAG, "第一次定位");
intent.putExtra("GPS_info", "第一次定位");
sendBroadcast(intent);
break;
case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
// 獲取當前狀態
gs = locationManager.getGpsStatus(null);
int maxSatellites = gs.getMaxSatellites();// 獲取衛星顆數的默認最大值
Iterator<GpsSatellite> iters = gs.getSatellites().iterator();
// 創建一個迭代器保存所有衛星
int count = 0;
String info = "";
while (iters.hasNext() && count <= maxSatellites) {
GpsSatellite s = iters.next();
count++;
info += count + "\t:" + s.getPrn() + "\t信噪比:" + s.getSnr()
+ "\t方位角:" + s.getAzimuth() + "\t海拔:"
+ s.getElevation() + "\n";
}
if (count != 0)
Status = "\n搜索到:" + count + "顆衛星\n" + info;
else
Status = "\n未搜索到衛星\n";
// Log.i(TAG, "您當前的位置是:\n" + lastLocation + Status);
intent.putExtra("GPS_info", "您當前的位置是:\n" + lastLocation
+ Status);
sendBroadcast(intent);
break;
case GpsStatus.GPS_EVENT_STARTED:// 定位啟動
Log.i(TAG, "定位啟動");
intent.putExtra("GPS_info", "定位啟動");
sendBroadcast(intent);
break;
case GpsStatus.GPS_EVENT_STOPPED:// 定位結束
Log.i(TAG, "定位結束");
intent.putExtra("GPS_info", "定位結束");
sendBroadcast(intent);
break;
}
}
示例6: onGpsStatusChanged
import android.location.GpsSatellite; //導入方法依賴的package包/類
/**
* This method is automatically called when the status of the Gps changes. In this program
* we use it to detect the firstFix event that can be used to disable the firstFixTimeouts of
* many listeners and start the operationTimeout for them.
*/
@Override
public void onGpsStatusChanged(int event) {
//update the local copy of gpsStatus
if(gpsStatus != null) {
synchronized(gpsStatus) {
locManager.getGpsStatus(gpsStatus);
}
}
else {
gpsStatus = locManager.getGpsStatus(null);
}
switch (event) {
case GpsStatus.GPS_EVENT_FIRST_FIX:
//iterate over the listeners collection and make firstFixReceived true
Log.v(TAG, "First fix received");
break;
case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
int numberOfSatellites = 0;
int numberOfSatellitesUsedInFix = 0;
synchronized(gpsStatus) {
Iterable<GpsSatellite> satellites = gpsStatus.getSatellites();
for(GpsSatellite sat : satellites){
if (sat.getSnr() > 10)
numberOfSatellites++;
if (sat.usedInFix())
numberOfSatellitesUsedInFix++;
}
}
if (numberOfSatellites != mNumberOfSatellites)
{
try{
setNumberOfSatellites(numberOfSatellites);
//if (listeners.size() > 0 && (!listeners.get(0).isFirstFixReceived() || numberOfSatellitesUsedInFix > 0))
if (listeners != null && listeners.size() > 0 && (numberOfSatellitesUsedInFix > 0 || numberOfSatellites > 0))
//Log.v(TAG, String.format("Gps status changed; numberOfSatellites:%d; numberOfSatellitesUsedInFix:%d", numberOfSatellites, numberOfSatellitesUsedInFix));
owner.updateNumberOfSatellites(numberOfSatellites, numberOfSatellitesUsedInFix);
Location lastloc = owner.getLastLocation ();
if (lastloc == null || !lastloc.getProvider().equals(LocationManager.GPS_PROVIDER)) // || lastloc.getTime() < System.currentTimeMillis() - 10000 )
{
for (int i=0; i<listeners.size(); i++) {
GpsListener listener = listeners.get(i);
if (listener.getProvider().equals(LocationManager.GPS_PROVIDER))
listener.onLocationUpdate(null,0);
}
}
}
catch (Exception e) {}
}
break;
case GpsStatus.GPS_EVENT_STARTED:
owner.broadcastGpsStatus(true);
Intent intent = new Intent(IntentHandler.GPS_STATE_ON);
owner.sendBroadcast(intent);
break;
case GpsStatus.GPS_EVENT_STOPPED:
owner.updateNumberOfSatellites(0, 0);
owner.broadcastGpsStatus(false);
Intent intent2 = new Intent(IntentHandler.GPS_STATE_OFF);
owner.sendBroadcast(intent2);
break;
}
}