简体   繁体   English

我无法从Google Maps API获取准确的GPS位置以在Android上使用

[英]I'm having trouble getting accurate GPS locations from the Google Maps API for use on Android

We are developing an application for people to mark areas (single points, lines, and polygons) on Google Maps using Android phones (2.1 and up). 我们正在开发一个应用程序,供人们使用Android手机(2.1及更高版本)在Google地图上标记区域(单点,直线和多边形)。 They are given a Google Maps view and enter the points for the lines by centering the screen at the location that they want to create a point and then press a button on the GUI to add the point at that location. 他们将获得Google Maps视图,并通过将屏幕居中放置在要创建点的位置来输入直线的点,然后按GUI上的按钮以在该位置添加点。

After entering a point, they recenter the screen on the location for the next point and press the create point button again. 输入点后,他们将屏幕重新显示到下一个点的位置,然后再次按创建点按钮。 After all of the points for that shape have been entered, they switch to another view where they enter some descriptive information and send the information to a central database. 输入该形状的所有点后,它们会切换到另一个视图,在其中输入一些描述性信息并将该信息发送到中央数据库。

Unfortunately, the points shift by a small amount relative to the locations they were supposed to mark. 不幸的是,这些点相对于它们应该标记的位置有少量的偏移。 If the user switches from the summary view back to the point editing view, all of the points will have shifted, some by only a foot and some by as much as 10 or 15 feet. 如果用户从摘要视图切换回点编辑视图,则所有点都将移动,有些仅移动了一英尺,有些移动了多达10或15英尺。 The problem appears to be that 问题似乎是

GeoPoint point = mapView.getMapCenter();

returns inaccurate GPS coordinates after the view has been panned. 平移视图后,返回不正确的GPS坐标。 When the points are rendered to a fresh view, they are consistently shown at the same position which correlate well with Google maps views on the internet for those same GPS coordinates. 将这些点渲染为新视图时,它们会始终显示在同一位置,该位置与互联网上针对相同GPS坐标的Google地图视图之间具有很好的相关性。 We have extensively debugged the software and the coordinates have the wrong map location / GPS coordinates when they are returned from mapView.getMapCenter(); 我们已经对软件进行了广泛的调试,当从mapView.getMapCenter();返回时,坐标具有错误的地图位置/ GPS坐标mapView.getMapCenter();

Because we were concerned that the 因为我们担心

Point p = new Point();
mapView.getProjection().toPixels(mapView.getMapCenter(), p); 

might not return the screenWidth / 2 , screenHeight / 2 location, we actually show the cross-hair used to place points at the toPixels location and the newly created points match up exactly with the cross-hair when they are originally created. 可能不会返回screenWidth / 2screenHeight / 2位置,我们实际上显示了用于在toPixels位置放置点的十字准线,并且新创建的点与最初创建时的十字准线完全匹配。 After changing to the summary screen and back, they are re-rendered at their real GPS coordinates. 切换到摘要屏幕并返回后,它们将以其真实的GPS坐标重新渲染。

Also, to be clear, this has nothing to do with the accuracy of the GPS sensor. 另外,需要明确的是,这与GPS传感器的精度无关。

If we could refresh / reinitialize the map view after panning, it might be awkward, but it would be an improvement over our current problems. 如果我们可以在平移后刷新/重新初始化地图视图,则可能会很尴尬,但这将是对当前问题的一种改进。 Moving to other map software, meanwhile, would take a lot of time and might have its own problems. 同时,转移到其他地图软件将花费很多时间,并且可能会有自己的问题。

I do something similar and have no trouble with inaccuracy. 我做类似的事情,并且在准确性方面没有问题。 I suspect it's the way you are placing your crosshairs. 我怀疑这是您放置十字准线的方式。 I define mine in the main.xml using a Unicode character and pin it to the view centre using this snippet: 我使用Unicode字符在main.xml中定义了我的代码,并使用以下代码段将其固定到视图中心:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#0000ff"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <include
        layout="@layout/googlemap"/>
    <Button
        android:text='\u25ce'
        android:id="@+id/BullseyeButton"
        android:background="@android:color/transparent"
        android:layout_centerInParent="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="24pt"
        android:typeface="monospace"
        android:textColor="#afffff00"></Button>
    <include
        layout="@layout/infobar"/>
</RelativeLayout>

The centerInParent attribute guarantees that both the crosshairs and the mapview are using the same centre. centerInParent属性可确保十字线和地图视图使用同一中心。

The u25ce make a pretty good indicator for me. u25ce对我来说是一个很好的指标。 There are other ones that you might find better. 还有其他一些您可能会发现更好的。

Update 更新资料

Well I update my app's info bar once per second with a handler. 好吧,我使用处理程序每​​秒更新一次我的应用程序的信息栏。 I added this test method to be called in the handler 我添加了此测试方法以在处理程序中调用

protected void backAndForth(MapView mv){
    GeoPoint centreGpt = mv.getMapCenter();
    int inLon = centreGpt.getLongitudeE6();
    int inLat = centreGpt.getLatitudeE6();
    Point p = new Point();
    mv.getProjection().toPixels(centreGpt, p);
    GeoPoint backGpt = mv.getProjection().fromPixels(p.x, p.y);
    int outLat = backGpt.getLatitudeE6();
    int outLon = backGpt.getLongitudeE6();
    String res = "In lat " + inLat + " In lon " + inLon 
                + " Out lat " + outLat + " Out lon " + outLon;
    Log.d("POS_TAG", res);
}

The in and out coordinates match perfectly no matter how I pan and zoom. 无论我如何平移和缩放,输入和输出坐标都完全匹配。 using the reverse geocoder, jumping from Chicago to London to Berlin, I get output from the test method: 使用反向地理编码器,从芝加哥到伦敦再到柏林,我从测试方法中获得了输出:

In lat 41878113 In lon -87629798 Out lat 41878113 Out lon -87629798
In lat 41878113 In lon -87629798 Out lat 41878113 Out lon -87629798
In lat 51500152 In lon -126236 Out lat 51500152 Out lon -126236
In lat 51500152 In lon -126236 Out lat 51500152 Out lon -126236
In lat 51500152 In lon -126236 Out lat 51500152 Out lon -126236
In lat 52523405 In lon 13411399 Out lat 52523405 Out lon 13411399
In lat 52523405 In lon 13411399 Out lat 52523405 Out lon 13411399
In lat 52523405 In lon 13411399 Out lat 52523405 Out lon 13411399

I'm afraid you've got me stumped 恐怕你让我难过

Update 更新资料

I changed my application to display 6 places of decimals from its normal 5 and chose an intersection of car park bays in a supermarket near me in London. 我将应用程序更改为显示正常小数点后6位小数,并在伦敦附近的一家超市中选择了一个停车位交叉点。 I did as you suggested and took screen shots at maximum zoom from my emulator at the start and after I'd panned and zoomed and panned back to the original place as close as I could without looking at the displayed Lat/Lon as I did it. 我按照您的建议做了,并在开始时从模拟器上以最大缩放比例拍摄了屏幕快照,然后平移,缩放并平移回了原始位置,而没有像我那样看显示的纬度/经度。 。 These are typical results 这些是典型的结果

Start 开始 开始

End 结束 在此处输入图片说明

1 microdegree is only about 11 centimetres for change in latitude and about 6cm for change in longitude at this latitude, so I reckon this is pretty much within my ability to pan accurately. 1微度的纬度变化大约只有11厘米,经度的变化只有6厘米,因此我认为这在我准确摇摄的能力范围内。

Google maps themselves seem to have bigger inherent display errors. Google地图本身似乎具有更大的固有显示错误。 For example, the UK's mapping agency (The Ordnance Survey) maintains a number of triangulation points around the country. 例如,英国的测绘机构(The Ordnance Survey)在全国范围内维护了许多三角测量点。 These are fixed by satellite reference on the WGS84 datum to within sub millimetric accuracy. 这些通过WGS84基准面上的卫星参考固定在亚毫米精度内。 They are normally quarter inch copper studs set into concrete. 它们通常是四分之一英寸的铜螺柱,固定在混凝土中。 One which we can correlate with a Google map view is at 我们可以将其与Google地图视图关联的位置为

Ham trig point 火腿切点

There's sketch of its location at: 在以下位置有其位置的示意图:

Sketch 草图

and a photo on this site (The bolt is under the dog's front right paw): 和此站点上的照片(螺栓在狗的右前爪下方):

Trig point photo 触发点照片

If you look at a screen shot of my app geo fixing to that location 如果您查看我的应用程序对该位置进行地理定位的屏幕截图

在此处输入图片说明

You can see that Google has the spot as a good 6 feet beyond the edge of the jetty and would be in the water at high tide. 您会看到Google在离码头边缘6英尺处有一个不错的位置,并且将在涨潮时进入水中。

In conclusion, I think that any errors I see in terms of repeatability are swamped by those inherent in Google's interpretation of a coordinate. 总之,我认为我在可重复性方面看到的任何错误都会被Google解释坐标所固有的错误所淹没。 This is probably to be expected as I know they use a simple spherical projection of the Earth's surface, rather than the more accurate ellipsoidal one on which GPS systems are based. 据我所知,这是可以预料的,因为我知道他们使用的是地球表面的简单球形投影,而不是GPS系统所基于的更精确的椭圆形投影。

We eventually replaced Google Maps with Bing Maps in our android application, using the Android SDK from InKnowledge. 最终,我们使用InKnowledge的Android SDK在我们的android应用程序中将Google Maps替换为Bing Maps。 They are providing accurate GPS coordinates for the center of the map view, which we use to build polygons, polylines, and pushpin shapes. 它们为地图视图的中心提供了准确的GPS坐标,我们可以使用它们来构建多边形,折线和图钉形状。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM