Get nearby places from a custom markers

谁说胖子不能爱 提交于 2019-12-24 00:24:59

问题


I have a list of markers and would like to get the nearby place using my list of markers. I have tried checking it here but it is not clear as to how they solve the problem. The following is my code that I've implemented so far:

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;
        }
    });
}
}

Please guide me and help me as to how do I achieve the desired results.

来源:https://stackoverflow.com/questions/47351094/get-nearby-places-from-a-custom-markers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!