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)
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);
First , I'am Chinese ,and I use the Gaode Map(aMap.com),and while I run this
aMap.addPolyline(new
PolylineOptions().add(drawLineLastLatlng,latlng).width(10)
.color(Color.argb(255, 1, 255, 255)))
the Exception "southern latitude exceeds northern latitude" occurs; then I check the class and find the sentence at LineNumber 35, then I change my codes like this ,and questions resolved :
if(drawLineLastLatlng!=null&&drawLineLastLatlng.latitude!=latlng.latitude){
if(latlng.latitude>drawLineLastLatlng.latitude){
aMap.addPolyline(new PolylineOptions().add(drawLineLastLatlng,latlng).width(10)
.color(Color.argb(255, 1, 255, 255)));
}else{
aMap.addPolyline(new PolylineOptions().add(latlng,drawLineLastLatlng).width(10)
.color(Color.argb(255, 1, 255, 255)));
}
}
This exception basically happens while creating LatLngBounds object with wrong LatLng points. southwest Latlong should be first and northwest should be 2nd parameter. check this link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With