【问题标题】:How to get longitude and latitude from firebase real time database and display the location markers in Google Maps API?如何从 Firebase 实时数据库中获取经度和纬度并在 Google Maps API 中显示位置标记?
【发布时间】:2019-05-13 05:23:51
【问题描述】:

我正在构建一个 android 应用程序来跟踪多个设备的位置。我使用该应用程序将设备的经度和纬度保存到 Firebase,但我不知道如何从 Firebase 检索经度和纬度并将它们显示为 Google 地图中的标记。

【问题讨论】:

  • 欢迎来到SO,请参考stackoverflow.com/help/how-to-ask
  • 如何保存纬度和经度?它们可能只保存了 2 个双精度值。所以你需要将它们作为 2 个双精度值来获取。

标签: android firebase firebase-realtime-database google-maps-api-3 google-maps-markers


【解决方案1】:

我不知道你怎么做 firebase 部分,但是一旦你有了信息,你需要做这样的事情:

LatLng location = new LatLng(latitude, longitude);
googleMap.addMarker(new MarkerOptions().position(location).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));

onMapReady 中,要添加具有自定义值的新标记,如果您要拥有很多标记,我建议您查看clustering

【讨论】:

    【解决方案2】:
        LatLng latLng = new LatLng(latitude, longitude);
        MarkerOptions markerOptions = new MarkerOptions();
        markerOptions.position(latLng);
        markerOptions.title("Current Position");
        markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin_black));
        mMap.addMarker(markerOptions);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-07
      • 1970-01-01
      • 2021-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多