Android Google Service Place picker setLatLngBounds() not working
Asked Answered
E

1

11

I am using PlacePicker in my App. All of sudden its behaving badly. When its launched its pointing to (0.0, 0.0) lat lng. I am not sure if Google service changed something. earlier it was working all fine since from 3 days its not working.

Am I doing anything wrong here

This is How I am launching Activity.

private void launchPlacePicker(double latitude, double longitude) {
    try {
        showProgress(true);
        PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();

        Log.d(TAG, " launchPlacePicker " + latitude + " " + longitude);

        builder.setLatLngBounds(MapUtils.getLatLngBounds(new LatLng((double) latitude, (double) longitude)));

        startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
    } catch (GooglePlayServicesRepairableException e) {
        showProgress(false);
        Log.e(TAG, "GooglePlayServicesRepairableException", e);
    } catch (GooglePlayServicesNotAvailableException e) {
        showProgress(false);
        Log.e(TAG, "GooglePlayServicesNotAvailableException", e);
    }
}

This is how I am creating LatLngBounds

public static LatLngBounds getLatLngBounds(LatLng center) {
    double radius = 100;
    LatLng southwest = SphericalUtil.computeOffset(center, radius * Math.sqrt(2.0), 225);
    LatLng northeast = SphericalUtil.computeOffset(center, radius * Math.sqrt(2.0), 45);
    return new LatLngBounds(southwest, northeast);
}

and I tried to create LatLngBounds like below, still same result.

public static LatLngBounds getLatLngBounds(LatLng center) {
    LatLngBounds.Builder builder = LatLngBounds.builder();
    builder.include(center);
    return builder.build();
}

could some one help me

Emendate answered 18/5, 2016 at 10:32 Comment(0)
F
15

Unfortunately you are going to have to wait for Google to fix the issue in a future release of Google Play Services.

There is not anything wrong with your code, the latest update of Google Play Services causes some serious issues with the Place Picker UI widget. I first noticed the setLatLngBounds() method no longer works in Google Play Services 9.0.82. In 9.0.83, the search icon disappeared.

See my post regarding this issue: Android PlacePicker no longer has Search icon after updating to Google Play Services 9.0.83

See these bug reports from the Google Maps API bug and feature website: Bug: Search Icon not visible in the latest play service update (Version:9.0.83) ----- Bug: Place Picker not showing search icon. ----- PlacePicker search icon is gone after updating to Google Play Services 9.0.83

You can somewhat work around the issue by not invoking the setLatLngBounds() method. PlacePicker will default to your current location. I lost some functionality in my app, but it was better than having the end user try to pinch and pan their way back from the Atlantic Ocean. For me, the missing search icon is still my major issue.

Federalize answered 19/5, 2016 at 8:36 Comment(2)
The setLatLngBounds() problem in Place Picker should be fixed in the current release of Google Play Services (Jun-26)Billybillycock
I know this question is old, but I have similar problem, PlacePicker not defaulting to my currentl location when launched, it starts with location selected previously and I need to tap "my location' icon to get marker to be moved to my location. Any ideas how to force PlacePicker to my current location by default when launched?Reata

© 2022 - 2024 — McMap. All rights reserved.