【问题标题】:Google maps - LatLng change my values in android谷歌地图 - LatLng 改变我在 android 中的值
【发布时间】:2013-12-19 03:12:54
【问题描述】:

我对谷歌地图中的经度和纬度有疑问。 这就是我添加标记的方式:

Marker newStore = map.addMarker(new MarkerOptions().position(new LatLng(store.getLatitude(), store.getLongitude()))
                    .title(store.getName()).icon(BitmapDescriptorFactory.defaultMarker(markerResolver("up"))));

store.getLatitude = 44.04687store.getLongitude = -70.295734。 当我添加它们后打印标记位置时,这就是我得到的: marker.getPosition().latitude = 44.046873756marker.getPosition().longitude = -70.295734543234。 现在我想将两个数据相等以按位置搜索我的商店,但我不能这样做,因为商店位置与标记位置不同。标记位置比 sote 位置更精确。我怎样才能避免这种情况。我问这个是因为我有一个商店列表并按位置添加标记。现在我想按位置获取我点击的商店,但你可以看到标记和 sotre 的位置不同。

【问题讨论】:

  • 为什么在创建标记时不将商店名称或其他内容放在标记的 sn-p 中,这样当单击它时,您所要做的就是查看 sn-p 以查看哪个商店这是。或者只是从您已经放置它的标题中获取它
  • 天啊,这么简单...非常感谢。我不知道为什么我跳过sn-p我选择这种方式:)

标签: android google-maps-android-api-2


【解决方案1】:

您不应该根据LatLng 的位置比较Markers 或任何其他对象,因为this bug

您可以将所有Markers 和Stores 保留为Map<Marker, Store>,然后在onMarkerClick 中像这样检索它:

Store store = map.get(marker);

在此处了解有关该方法和其他方法的更多信息:https://stackoverflow.com/a/17000070/2183804

【讨论】:

    【解决方案2】:

    一种选择是利用 Geohashing 的概念根据两点之间的接近程度来评估相等性。 Geohashes 大小(距离)可以在实例化时配置。因此,在您的示例中,您可以像这样构造 Geohashes:

    GeoHash myLocHash = GeoHash.withCharacterPrecision(store.getLatitude(), store.getLongitude(), 7);
    GeoHash markerLocHash = GeoHash.withCharacterPrecision(marker.getPosition().latitude, marker.getPosition().longitude, 7);
    
    if (myLocHash.equals(markerLocHash)) {
        // Same location +/- .61 km margin of error
    }
    

    这对于您需要的东西来说可能是多余的,但对于其他应用程序来说可能是一个非常方便的选择。这是一个很棒的 Geohashes Java 库:

    https://github.com/kungfoo/geohash-java

    更多关于 Geohashes 的阅读:

    http://en.wikipedia.org/wiki/Geohash

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-10
      • 2014-08-03
      • 1970-01-01
      相关资源
      最近更新 更多