Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Google Service Place picker setLatLngBounds() not working

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

like image 895
Sharanabasu Angadi Avatar asked May 18 '16 10:05

Sharanabasu Angadi


1 Answers

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.

like image 94
Dan Ross Avatar answered Nov 09 '22 23:11

Dan Ross