比较google map v2 android中的两个LatLng对象 [英] Comparing two LatLng objects in google map v2 android

查看:196
本文介绍了比较google map v2 android中的两个LatLng对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由latlong对象组成的数组列表,如下所示:

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

注意:LatLng是一种双重格式的纬度和经度值的对象,即纬度是双格式,经度为双格式



以下是存储在上述 latLngList 对象中的值:长度列表:[lat / lng:(34.072516,-118.403609),lat / lng:(34.074227,-118.399248)

  (34.07304,-118.3995),lat / lng:(34.07304,-118.3995),lat / lng:(34.07304,-118.3995),lat / lng:(34.067856,-118.401485)] 

现在,由于我在Android中处理谷歌地图v2,每当我点击一个特定的标记,我得到纬度和经度位置,我尝试将其与 latLngList 对象进行比较,以查找该对象是否存在于 latLngList 中。



我以下列方式进行:

  for(LatLng latLng:latLngList){
marker.get 。位置()等于(的latLng); **总是返回false **
}

标记位置正在返回以下latLng对象:

  lat / lng:(34.074226888265116,-118.39924816042185)
pre>

很显然,标记返回的纬度和经度对象有点冗长,因此比较失败。


解决方案

更好的方法是不要比较基于 LatLng ,但标识为标记。对于一些奇怪的原因, Marker.getPosition()不会返回完全相同的值。



我建议将所有标记存储在列表地图中,如果要为每个附加一些附加信息标记



或者您可以在创建 Marker.getId() code>标记,存储它,然后比较 onMarkerClick



编辑



我也在 gmaps-api-issues


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

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

Note: LatLng is an object which has latitude and longitude values in double format i.e., Latitude is in double format and Longitude is in double format

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)]

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.

I am doing it in the following way:

 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?

解决方案

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.

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

Edit:

I have also reported this on gmaps-api-issues.

这篇关于比较google map v2 android中的两个LatLng对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆