如果它们在Radius内,则在地图上显示用户

时间:2017-05-18 06:18:26

标签: android google-maps

当我点击地图时,我将所有用户的LatLng存储在SharedPreference中。现在我画一个圆圈然后如果任何用户进入这个圆圈,那么标记应该是可见的。我能够做到这一切,但它只显示一个用户。但是我的共享偏好中有多个LatLng。我该怎么办?请跟我说我的代码在这里

 private void calculateUserLocation(MapAreaWrapper draggableCircle) {
    float[] distance = new float[10];

    Location.distanceBetween(map_flag.getPosition().latitude, map_flag.getPosition().longitude,
            draggableCircle.getCenter().latitude, draggableCircle.getCenter().longitude, distance);

    if (distance[0] > draggableCircle.getRadius()) {
        Toast.makeText(getBaseContext(), "Outside", Toast.LENGTH_LONG).show();
    } else {
        map_flag.setVisible(true);
        Toast.makeText(getBaseContext(), "Inside", Toast.LENGTH_LONG).show();

    }
}

1 个答案:

答案 0 :(得分:1)

 private Marker mMarker;

     private void calculateUserLocation(MapAreaWrapper draggableCircle) {
        float[] distance = new float[10];

        Location.distanceBetween(map_flag.getPosition().latitude, map_flag.getPosition().longitude,
                draggableCircle.getCenter().latitude, draggableCircle.getCenter().longitude, distance);

        if (distance[0] > draggableCircle.getRadius()) {
            Toast.makeText(getBaseContext(), "Outside", Toast.LENGTH_LONG).show();
        } else {
            map_flag.setVisible(true);
     if (map!=null){


//Simple Marker 
        Marker hamburg = map.addMarker(new MarkerOptions().position(LatLng)
                .title("Hamburg"));

//marker With icon 
        Marker kiel = map.addMarker(new MarkerOptions()
                .position(LatLng)
                .title("Kiel")
                .snippet("Kiel is cool")
                .icon(BitmapDescriptorFactory
                        .fromResource(R.drawable.ic_launcher)));
    }

            Toast.makeText(getBaseContext(), "Inside", Toast.LENGTH_LONG).show();

        }
    }