Android google maps,google places, northern latitude exceeds southern latitude

android, google-maps, google-places-api

Solution

Make use of LatLngBounds.Builder class to include your LatLng using .include(). It will prevent this error.

LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(currentLocation).include(streetLocation);

//Animate to the bounds
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(builder.build(), 100);
mMap.moveCamera(cameraUpdate);

Problem

I am using google maps and use JSON to parse cafe around my location from google places. When I start navigation to the chosen a cafe from my current location 95% cafe I get a polyline but on some I get error like northern latitude exceeds southern latitude and app crashes. Here is my logcat: ``` 07-07 18:11:46.037: E/AndroidRuntime(25854): FATAL EXCEPTION: main 07-07 18:11:46.037: E/AndroidRuntime(25854): java.lang.IllegalArgumentException: southern latitude exceeds northern latitude (30.7223365 > 30.722303) 07-07 18:11:46.037: E/AndroidRuntime(25854): at com.google.android.gms.internal.fq.a(Unknown Source) 07-07 18:11:46.037: E/AndroidRuntime(25854): at com.google.android.gms.maps.model.LatLngBounds.<init>(Unknown Source) 07-07 18:11:46.037: E/AndroidRuntime(25854): at com.google.android.gms.maps.model.LatLngBounds.<init>(Unknown Source) 07-07 18:11:46.037: E/AndroidRuntime(25854): at com.example.google_map_ex.MainActivity.findDirections(MainActivity.java:285) 07-07 18:11:46.037: E/AndroidRuntime(25854): at com.example.google_map_ex.MainActivity$JSONParse$1.onItemClick(MainActivity.java:366) 07-07 18:11:46.037: E/AndroidRuntime(25854): at android.widget.AdapterView.performItemClick(AdapterView.java:301) 07-07 18:11:46.037: E/AndroidRuntime(25854): at android.widget.AbsListView.performItemClick(AbsListView.java:1490) 07-07 18:11:46.037: E/AndroidRuntime(25854): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3275) 07-07 18:11:46.037: E/AndroidRuntime(25854): at android.widget.AbsListView$1.run(AbsListView.java:4518) 07-07 18:11:46.037: E/AndroidRuntime(25854): at android.os.Handler.handleCallback(Handler.java:725) 07-07 18:11:46.037: E/AndroidRuntime(25854): at android.os.Handler.dispatchMessage(Handler.java:92) 07-07 18:11:46.037: E/AndroidRuntime(25854): at android.os.Looper.loop(Looper.java:137) 07-07 18:11:46.037: E/AndroidRuntime(25854): at android.app.ActivityThread.main(ActivityThread.java:5283) 07-07 18:11:46.037: E/AndroidRuntime(25854): at java.lang.reflect.Method.invokeNative(Native Method) 07-07 18:11:46.037: E/AndroidRuntime(25854): at java.lang.reflect.Method.invoke(Method.java:511) 07-07 18:11:46.037: E/AndroidRuntime(25854): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) 07-07 18:11:46.037: E/AndroidRuntime(25854): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 07-07 18:11:46.037: E/AndroidRuntime(25854): at dalvik.system.NativeStart.main(Native Method) ```

Original source