在谷歌地图V2的android比较两个LatLng对象对象、两个、地图、android

2023-09-05 00:28:24 作者:独爱甜心

我有一个ArrayList其中包括经纬度对象,如下所示:

I have an arraylist which consists of latLong object as shown below:

ArrayList < LatLng > latLngList = new ArrayList< LatLng >();

注意:经纬度是一个对象,它有经纬度值双格式即纬度是双格式和经度是双格式为:

的下面是它们被存储在值以上的 latLngList 对象

The below are the values which are stored in the above latLngList object:

Lat Long List:[lat/lng: (34.072516,-118.403609), lat/lng: (34.074227,-118.399248), lat/lng: (34.07304,-118.3995), lat/lng: (34.07304,-118.3995), lat/lng: (34.07304,-118.3995), lat/lng: (34.067856,-118.401485)]

现在,因为我用谷歌地图V2处理在Android中,每当我点击一个特定的标记,我得到的经纬度位置,我尝试将其与 latLngList 对象中寻找是否比较对象是present在 latLngList

Now, since i am dealing with google map v2 in android, whenever i click on a particular marker i get the latitude and longitude position and i try to compare it with the latLngList object to find whether the object is present in the latLngList.

我这样做以下列方式:

 for(LatLng latLng : latLngList) {
       marker.getPosition().equals(latLng); **Always returns false**
 }

标记位置返回我用下面的经纬度对象:

The marker position is returning me with the following latLng object:

lat/lng: (34.074226888265116,-118.39924816042185)

显然,通过标记返回的纬度和经度对象是一个冗长位,因而比较失败。

It is clear that the latitude and longitude object returned by marker is a bit lengthy and hence the comparison fails.

有没有比较经纬度对象的更好的办法?

Is there a better way of comparing the latLng object?

推荐答案

一个更好的方法是不是比较的基础上经纬度标记,但在身份标记。出于某种奇怪的原因 Marker.getPosition()不返回完全相同的值。

A better way is not to compare markers based on LatLng, but on the identity of Marker. For some weird reason Marker.getPosition() doesn't return exactly the same value.

我建议存储中的所有标志物列表地图如果你要附加一些额外的信息每个标记

I'd suggest storing all markers in a List or Map if you want to attach some additional info to every Marker.

另外,您可以使用 Marker.getId()之后创建标记,储存和以后比较,在 onMarkerClick

Alternatively you may use Marker.getId() after you create Marker, store it and later compare that in onMarkerClick.

编辑:

我也报这个在 GMaps实现-API的问题。