从自定义标记获取附近的地方

时间:2017-11-17 12:51:44

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

我有一个标记列表,并希望使用我的标记列表来获取附近的地方。我试过检查它here但不清楚它们是如何解决问题的。以下是我到目前为止实施的代码:

public class LocationMapsNearby extends FragmentActivity implements OnMapReadyCallback {

private static final LatLng JOHANNESBURG = new LatLng(-26.196908, 28.042179);
private static final LatLng CAPETOWN = new LatLng(-33.971294, 18.602129);
private static final LatLng DURBAN = new LatLng(-29.865079, 30.989223);

private Marker mJoburg;
private Marker mCapeTown;
private Marker mDurban;
private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_location_maps_nearby);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.maps);
    mapFragment.getMapAsync(this);
}


/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
/**
 * Called when the map is ready.
 */
@Override
public void onMapReady(GoogleMap map) {
    mMap = map;

    // Add some markers to the map, and add a data object to each marker.
    mJoburg = mMap.addMarker(new MarkerOptions()
            .position(JOHANNESBURG)
            .title("Johannesburg"));
    mJoburg.setTag(0);

    mCapeTown = mMap.addMarker(new MarkerOptions()
            .position(CAPETOWN)
            .title("Cape Town"));
    mCapeTown.setTag(0);

    mDurban = mMap.addMarker(new MarkerOptions()
            .position(DURBAN)
            .title("Durban"));
    mDurban.setTag(0);

    // Set a listener for marker click.
    mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            // Retrieve the data from the marker.
            Integer clickCount = (Integer) marker.getTag();

            // Check if a click count was set, then display the click count.
            if (clickCount != null) {
                clickCount = clickCount + 1;
                marker.setTag(clickCount);
                Toast.makeText(LocationMapsNearby.this,
                        marker.getTitle() +
                                " has been clicked " + clickCount + " times.",
                        Toast.LENGTH_SHORT).show();
            }

            // Return false to indicate that we have not consumed the event and that we wish
            // for the default behavior to occur (which is for the camera to move such that the
            // marker is centered and for the marker's info window to open, if it has one).
            return false;
        }
    });
}
}

请指导我并帮助我如何达到预期的效果。

0 个答案:

没有答案