【问题标题】:How to display multiple static location in android?如何在android中显示多个静态位置?
【发布时间】:2018-04-06 08:55:20
【问题描述】:

我正在尝试在地图中与用户当前位置不同的位置显示标记。 现在我给了两个静态值

1.) LatLng one = new LatLng(12.9010, 80.2279);

2.) LatLng two = new LatLng(12.9229, 80.1275);
但它没有在地图中显示标记,我得到控制台输出有 lat long value 0,0。

这是我使用静态值获取地图中标记位置的代码。

private void addmap() {

    LatLng one = new LatLng(12.9010, 80.2279);
    LatLng two = new LatLng(12.9229, 80.1275);

    LatLngBounds.Builder builder = new LatLngBounds.Builder();

    //add them to builder
    builder.include(one);
    builder.include(two);

    LatLngBounds bounds = builder.build();

    //get width and height to current display screen
    int width = getResources().getDisplayMetrics().widthPixels;
    int height = getResources().getDisplayMetrics().heightPixels;

    // 20% padding
    int padding = (int) (width * 0.20);

    //set latlong bounds
    Mmap.setLatLngBoundsForCameraTarget(bounds);

    //move camera to fill the bound to screen
    Mmap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding));

    //set zoom to level to current so that you won't be able to zoom out viz. 
  move outside bounds
//        Mmap.setMinZoomPreference(mMap.getCameraPosition().zoom);
}

【问题讨论】:

  • 检查您的 widthheight 值。

标签: java android google-maps geolocation latitude-longitude


【解决方案1】:

您可以将 lat long 放入列表中并循环设置多个标记

这里是示例

for (int i = 0; i < list.size(); i++) {

            Marker marker;
            marker = gMap.addMarker(new MarkerOptions().position(new LatLng(list.getLat(), list.getLng()))
                        .icon(BitmapDescriptorFactory.fromResource(R.mipmap.location_other))
                        .flat(true));
           }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-29
    • 2012-04-25
    • 2014-11-30
    • 1970-01-01
    • 2021-10-08
    相关资源
    最近更新 更多