GVKun编程网logo

android – 如何从nmea句子信息计算以米为单位的gps准确度

9

在这篇文章中,我们将带领您了解android–如何从nmea句子信息计算以米为单位的gps准确度的全貌,同时,我们还将为您介绍有关Android2.2下camera应用程序支持GPS信息写入jpeg文

在这篇文章中,我们将带领您了解android – 如何从nmea句子信息计算以米为单位的gps准确度的全貌,同时,我们还将为您介绍有关Android 2.2 下 camera 应用程序支持 GPS 信息写入 jpeg 文件、Android GPS 定位的实现(1)、Android GPS 获取当前位置 & GPS 信息更新、android – 如何从NDK C线程调用Java API?的知识,以帮助您更好地理解这个主题。

本文目录一览:

android – 如何从nmea句子信息计算以米为单位的gps准确度

android – 如何从nmea句子信息计算以米为单位的gps准确度

我有 Android应用程序,从蓝牙GPS接收器获取GPGGA和GPRMC句子,如何计算给定位置的水平精度与米?

解决方法

如果您按照评论中的说明以米为单位提供HDOP,那么您将提供完全错误的幻想价值.

作为与实际问题相关的替代答案,我只是想提供一个相关的链接到GIS Stackexchange网站,在那里也提出了这个问题:https://gis.stackexchange.com/questions/97774/how-can-i-convert-horizontal-dilution-of-position-to-a-radius-of-68-confidence

简而言之:它并非无足轻重,仅靠HDOP并不足以获得可靠的准确度.正如用户30184评论的那样,有些人只是使用例如将器件精度设为3-5 m,然后将其与HDOP相乘以获得精度.

但总的来说,让我引用一下this also provided link的claudegps:

You can’t. DOP is not an indicator of “error” or “accuracy”. Bad DOP
does not always mean bad accuracy for example. Moreover the “accuracy”
should not consider only DOP: Imagine to be indoor (very low signal,a
lot of multipath ecc) but with a good DOP: you may have a very bad
accuracy even with a good DOP… So your indication DOP-based will be
wrong. Unfortunately,if you have only NMEA sentences,you usually
don’t have enough data to estimate the accuracy (that can be done
internally to the receiver as it have much more informations inside).

你也可以看一下这个链接:https://www.gps-forums.com/threads/estimating-accuracy-from-raw-nmea-data.46273/最后但并非最不重要的,从this link开始:

6 sources of error (and additional factors) affect the accuracy of GPS positions

Android 2.2 下 camera 应用程序支持 GPS 信息写入 jpeg 文件

Android 2.2 下 camera 应用程序支持 GPS 信息写入 jpeg 文件

一、概述

在Android2.2中,Camera的应用程序并不支持将GPS信息写入到JPEG文件中,但如果要实现这个功能,有如下两种方式:

1、修改底层camera驱动。在拍照时,一般都是使用硬件去进行JPEG编码,这样就需要修改JPEG编码器,使其可以将GPS信息写入JPEG文件的头部,即EXIF部分。这种方式使用与手机驱动开发者。

2、修改camera应用程序。Camera应用程序本身不支持该功能,但是android系统中提供了支持该功能的类—— ExifInterface。本文介绍如何使用该类进行GPS信息的写入。这种方法的不足在于,每次写入GPS功能,都会把原有的JPEG文件读出,修改 了Exif header部分后再写入文件。

二、实现GPS写入功能

首先来看看文件ImageManager.java,该文件位于:

/package/apps/Camera/src/com/android/camera/

该文件中,有个addImage()函数,其定义为:

public static Uri addImage(ContentResolver cr, String title, long dateTaken,
 
        Location location, String directory, String filename,
        Bitmap source, byte[] jpegData, int[] degree) {
        。。。。。。
        String filePath = directory + "/" + filename;
        。。。。。。
        if (location != null) {
            values.put(Images.Media.LATITUDE, location.getLatitude());
            values.put(Images.Media.LONGITUDE, location.getLongitude());        
           }
       }
    return cr.insert(STORAGE_URI, values);
}

此处,当location不等于null时,表示已经开启存储位置的功能,并且该手机的GPS功能已开启并且正常。在这里,我们就可以把GPS的信息写入JPEG文件中。其具体code如下:

public static Uri addImage(ContentResolver cr, String title, long dateTaken,
            Location location, String directory, String filename,
            Bitmap source, byte[] jpegData, int[] degree) {
        。。。。。。
        String filePath = directory + "/" + filename;
        。。。。。。
 
        if (location != null) {
            values.put(Images.Media.LATITUDE, location.getLatitude());
            values.put(Images.Media.LONGITUDE, location.getLongitude());
           ExifInterface exif = null;
        try {
            exif = new ExifInterface(filePath);
        } catch (IOException ex) {
            Log.e(TAG, "cannot read exif", ex);
           }
         exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, Double.toString(location.getLatitude()));        
           exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, Double.toString(location.getLongitude()));
           try{
               if(exif != null)
              exif.saveAttributes();
           } catch (IOException ex) {
              Log.e(TAG, "Fail to exif.saveAttributes().");
           }
       }
    return cr.insert(STORAGE_URI, values);
}

三、分析GPS写入功能的实现

首先看看类ExifInterface的构造函数,其位于:

/framework/base/media/java/android/media/ ExifInterface.java

其具体实现为:

public ExifInterface(String filename) throws IOException {
        mFilename = filename;
        loadAttributes();
}

其功能是从指定的文件中获取其Exif信息。函数loadAttributes()的定义为:

private void loadAttributes() throws IOException {
        // format of string passed from native C code:
        // "attrCnt attr1=valueLen value1attr2=value2Len value2..."
        // example:
        // "4 attrPtr ImageLength=4 1024Model=6 FooImageWidth=4 1280Make=3 FOO"
        mAttributes = new HashMap<String, String>();
 
        String attrStr;
        synchronized (sLock) {
            attrStr = getAttributesNative(mFilename);
        }
        ……
}

该函数从文件中读取Exif信息,并将其写入mAttributes中。函数

getAttributesNative(mFilename),调用了JNI接口,其定义位于:/external/jhead/main.c

static JNINativeMethod methods[] = {
  {"saveAttributesNative", "(Ljava/lang/String;Ljava/lang/String;)V", (void*)saveAttributes },
  {"getAttributesNative", "(Ljava/lang/String;)Ljava/lang/String;", (void*)getAttributes },
  {"appendThumbnailNative", "(Ljava/lang/String;Ljava/lang/String;)Z", (void*)appendThumbnail },
  {"commitChangesNative", "(Ljava/lang/String;)V", (void*)commitChanges },
  {"getThumbnailNative", "(Ljava/lang/String;)[B", (void*)getThumbnail },
};

函数setAttribute()的实现如下:
public void setAttribute(String tag, String value) {
        mAttributes.put(tag, value);
}

向mAttributes写入对应的项,比如经度和纬度信息。

最重要的函数saveAttributes(),它也是调用JNI接口。它负责将所有的Exif项写入到JPEG文件中。由于时间关系,就不做介绍了,具体代码请大家自己看,有问题的话,一起讨论。

文章出处:http://blog.csdn.net/wxzking/article/details/6584224

Android GPS 定位的实现(1)

Android GPS 定位的实现(1)

今天弄了一个多小时,写了一个GPS获取地理位置代码的小例子,包括参考了网上的一些代码,并且对代码进行了一些修改,希望对大家的帮助。具体代码如下:  要实用Adnroid平台的GPS设备,首先需要添加上权限,所以需要添加如下权限: 



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

具体实现代码如下:

首先判断GPS模块是否存在或者是开启:

复制代码
代码


    
    
    
private void openGPSSettings() { LocationManager alm = (LocationManager) this .getSystemService(Context.LOCATION_SERVICE); if (alm .isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) { Toast.makeText( this , " GPS模块正常 " , Toast.LENGTH_SHORT) .show(); return ; } Toast.makeText( this , " 请开启GPS! " , Toast.LENGTH_SHORT).show(); Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS); startActivityForResult(intent, 0 ); // 此为设置完成后返回到获取界面 }

复制代码

如果开启正常,则会直接进入到显示页面,如果开启不正常,则会进行到GPS设置页面:

获取代码如下:

复制代码
代码


    
    
    
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( " 无法获取地理信息 " ); } }

复制代码

这样子就能获取到当前使用者所在的地理位置了,至少如何下地图上实现,在下面将进行获取,并显示出来!对参考代码的人表示感谢!

Android GPS 获取当前位置 & GPS 信息更新

Android GPS 获取当前位置 & GPS 信息更新

最近在做 Android 手机应用开发,还是很有意思的。其实如果只是做简单手机应用开发而不是手机游戏开发的话,还是很简单的。把主要的控件掌握了,就可以开发简单的应用了。

下面主要说一下在 Android 中使用 GPS 功能。

开发由于 GPS 功能时,常与 Google Map 相关,因此先推荐一篇讲解 Google Map 的文章:
http://mobiforge.com/developing/story/using-google-maps-android

该文章详细的讲解了 Android 中如何使用 Google Map 的各种功能。文章甚好,强烈推荐。

看完了如上文章后,我们就来讲解下如何使用 GPS。

首先在 AndroidManifest.xml 中添加位置服务权限:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
然后再看如下代码例: 
LocationManager locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location loc = locMan.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (loc != null) {
    lat = loc.getLatitude();
    Log.d(TAG, "latitude: " + lat);
    lng = loc.getLongitude();
    Log.d(TAG, "longitude: " + lng);
}
先注册 LocationManager,然后就可以通过访问 getLastKnownLocation 得到当前的 GPS 坐标。是不是很简单。

既然是 GPS,我们当然不只是想知道当前的位置,更重要的是要随着位置的移动,GPS 信息也要更新。那么我们需要怎么做呢?

还先看如下代码例:
LocationListener locLis = new MyLocationListener();
locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 10,
                locLis);
...
...
...
public class MyLocationListener implements LocationListener {
    @Override
    public void onLocationChanged(Location loc) {
        if (loc != null) {
            p = new GeoPoint((int) (loc.getLatitude() * 1E6),
                    (int) (loc.getLongitude() * 1E6));
            mc.animateTo(p);
            mc.setZoom(14);
            mc.setCenter(p);
        }
    }

    @Override
    public void onProviderDisabled(String provider) {
    }

    @Override
    public void onProviderEnabled(String provider) {
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }
}
声明自己的 LocationListener 后,调用 requestLocationUpdates 方法,就可以得到最新的 GPS 信息。

常用方法说明:
public void requestLocationUpdates (String provider, long minTime, float minDistance, LocationListener listener)

当时间超过 minTime(单位:毫秒),或者位置移动超过 minDistance(单位:米),就会调用 listener 中的方法更新 GPS 信息。

官方文档中有如下说明:

1. minTime 的值最好是不小于 60000(即:1 分钟),这样会更加高效且节电。
2. 如果要尽可能实时的更新 GPS 信息,请将 minTime 和 minDistance 都设置成 0。 

android – 如何从NDK C线程调用Java API?

android – 如何从NDK C线程调用Java API?

我想从NDK C线程调用 Java API,但env-> FindClass()返回0.但是当我在主线程中调用Java API时,它工作得很好.我已经在线程中调用了AttachCurrentThread(),任何人都可以帮我吗?

这是源代码:

JAVA代码:

public class simple_test extends Activity {
    ...
    // This functin will be called in C++
    public void PrintNdkLog(String slog) {
        Log.e(logTagNDK,slog);
        return;
    }
}

C代码:

static JavaVM* g_JavaVM = NULL;

jobject getInstance(jnienv *env,jclass obj_class)
{
    jmethodID  c_id = env->getmethodID(obj_class,"<init>","()V");
    jobject obj = env->NewObject(obj_class,c_id);
    return obj;
}

// JNI OnLoad
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm,void* reserved)
{
    g_JavaVM = jvm;
    return JNI_VERSION_1_6;
}

// Call JAVA API "PrintNdkLog" in this function
void PrintNdkLog(char *lpLog)
{
    if (g_JavaVM == NULL)
        return;

    jnienv *env = NULL;
    g_JavaVM->GetEnv((void**)&env,JNI_VERSION_1_6);
    if (env == NULL)
        return;

    jclass cls = env->FindClass("com/myndk/simple_test");
    if (cls != 0) // **cls will be 0 when PrintNdkLog() is called in thread**
    {
        LOGE("FindClass error %p",cls);
    }
    else
    {
        jmethodID mid;
        jobject obj;
        obj = getInstance(env,cls);
        mid = env->getmethodID(cls,"PrintNdkLog","(Ljava/lang/String;)V");
        if (mid != 0)
        {
            jstring jstrMSG = env->NewStringUTF(lpLog);
            env->CallVoidMethod(obj,mid,jstrMSG);
        }
    }
}

// Call JAVA API in thread
static void* thread_test(void* ptr)
{
    jnienv *envLocal;
    int status = g_JavaVM->GetEnv((void **) &envLocal,JNI_VERSION_1_6);
    if (status == JNI_EDETACHED)
    {
        status = g_JavaVM->AttachCurrentThread(&envLocal,NULL);
        if (status != JNI_OK)
            LOGE("AttachCurrentThread Failed %d",status);
    }
    PrintNdkLog("bbb"); // This JAVA callback Failed,and printed "FindClass error"
}

// Create thread
int NdkThread(AFX_THREADPROC pfnThreadProc,LPVOID pParam,int nPriority)
{
    PrintNdkLog("aaa"); // This JAVA callback runs well
    pthread_t pid;
    pthread_create(&pid,NULL,thread_test,pParam);
}

解决方法

我现在解决了
在NDK本机线程中,只能调用静态Java API.如果调用env-> FindClass(),它将触发异常.
http://android.wooyd.org/JNIExample获得了细节信息.

我们今天的关于android – 如何从nmea句子信息计算以米为单位的gps准确度的分享就到这里,谢谢您的阅读,如果想了解更多关于Android 2.2 下 camera 应用程序支持 GPS 信息写入 jpeg 文件、Android GPS 定位的实现(1)、Android GPS 获取当前位置 & GPS 信息更新、android – 如何从NDK C线程调用Java API?的相关信息,可以在本站进行搜索。

本文标签: