tyczj / MapNavigator

Easy to use library to get and display driving directions on Google Maps v2 in Android
Apache License 2.0
235 stars 96 forks source link

Crash Question #1

Closed donaldhuebner closed 10 years ago

donaldhuebner commented 10 years ago

I am using SupportMapFragments in my application and it is crashing when implementing the library calling it as described in the readme. Could this be why?

tyczj commented 10 years ago

I have not tested this with SupportMapFragment (really forgot it existed to be honest) what is the error you get?

It probably has to do with using SupportMapFragment though.

paste the stack trace here

donaldhuebner commented 10 years ago

10-23 14:54:23.590: W/System.err(20136): org.json.JSONException: Index 6 out of range [0..6) 10-23 14:54:23.590: W/System.err(20136): at org.json.JSONArray.get(JSONArray.java:263) 10-23 14:54:23.590: W/System.err(20136): at org.json.JSONArray.getJSONObject(JSONArray.java:480) 10-23 14:54:23.590: W/System.err(20136): at com.tyczj.mapnavigator.Legs.parseSteps(Legs.java:28) 10-23 14:54:23.590: W/System.err(20136): at com.tyczj.mapnavigator.Legs.(Legs.java:15) 10-23 14:54:23.590: W/System.err(20136): at com.tyczj.mapnavigator.Route.parseRoute(Route.java:46) 10-23 14:54:23.590: W/System.err(20136): at com.tyczj.mapnavigator.Route.(Route.java:25) 10-23 14:54:23.590: W/System.err(20136): at com.tyczj.mapnavigator.Directions.parseDirections(Directions.java:42) 10-23 14:54:23.590: W/System.err(20136): at com.tyczj.mapnavigator.Directions.(Directions.java:26) 10-23 14:54:23.590: W/System.err(20136): at com.tyczj.mapnavigator.Navigator$PathCreator.doInBackground(Navigator.java:212) 10-23 14:54:23.590: W/System.err(20136): at com.tyczj.mapnavigator.Navigator$PathCreator.doInBackground(Navigator.java:1) 10-23 14:54:23.590: W/System.err(20136): at android.os.AsyncTask$2.call(AsyncTask.java:287) 10-23 14:54:23.590: W/System.err(20136): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 10-23 14:54:23.590: W/System.err(20136): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 10-23 14:54:23.590: W/System.err(20136): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 10-23 14:54:23.590: W/System.err(20136): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 10-23 14:54:23.595: W/System.err(20136): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 10-23 14:54:23.595: W/System.err(20136): at java.lang.Thread.run(Thread.java:856) 10-23 14:54:23.595: D/AndroidRuntime(20136): Shutting down VM 10-23 14:54:23.595: W/dalvikvm(20136): threadid=1: thread exiting with uncaught exception (group=0x411b02a0) 10-23 14:54:23.595: E/AndroidRuntime(20136): FATAL EXCEPTION: main 10-23 14:54:23.595: E/AndroidRuntime(20136): java.lang.NullPointerException 10-23 14:54:23.595: E/AndroidRuntime(20136): at com.tyczj.mapnavigator.Navigator$PathCreator.onPostExecute(Navigator.java:239) 10-23 14:54:23.595: E/AndroidRuntime(20136): at com.tyczj.mapnavigator.Navigator$PathCreator.onPostExecute(Navigator.java:1) 10-23 14:54:23.595: E/AndroidRuntime(20136): at android.os.AsyncTask.finish(AsyncTask.java:631) 10-23 14:54:23.595: E/AndroidRuntime(20136): at android.os.AsyncTask.access$600(AsyncTask.java:177) 10-23 14:54:23.595: E/AndroidRuntime(20136): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644) 10-23 14:54:23.595: E/AndroidRuntime(20136): at android.os.Handler.dispatchMessage(Handler.java:99) 10-23 14:54:23.595: E/AndroidRuntime(20136): at android.os.Looper.loop(Looper.java:137) 10-23 14:54:23.595: E/AndroidRuntime(20136): at android.app.ActivityThread.main(ActivityThread.java:4898) 10-23 14:54:23.595: E/AndroidRuntime(20136): at java.lang.reflect.Method.invokeNative(Native Method) 10-23 14:54:23.595: E/AndroidRuntime(20136): at java.lang.reflect.Method.invoke(Method.java:511) 10-23 14:54:23.595: E/AndroidRuntime(20136): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008) 10-23 14:54:23.595: E/AndroidRuntime(20136): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775) 10-23 14:54:23.595: E/AndroidRuntime(20136): at dalvik.system.NativeStart.main(Native Method)

donaldhuebner commented 10 years ago

Hope this helps I'm still a bit of a newbie.

tyczj commented 10 years ago

ahh I see the problem, to fix it quick just set implement a listener for OnPathSetListener and it should work

example nav.setOnPathSetListener(this); and in your activity implement OnPathSetListener.

I will put a fix in to check to see if this was set or not

donaldhuebner commented 10 years ago

I tried that too before contacting you and I may have put it in the wrong place. Okay I'll put that in the same place where I'm calling the lib. Thank you.

donaldhuebner commented 10 years ago

THANK YOU FIXED. I swear I tried that reading your directions clearly. I had to set a new onPathSetListner I guess because of where I have it in the code. FIXED though after two days. Thank you.

donaldhuebner commented 10 years ago

Thank you.. mine looks like this.. I get the first latlng and second somewhere else.

//googleMap.animateCamera(CameraUpdateFactory.zoomTo(12)); //googleMap.addMarker(new MarkerOptions().position(latlng2)); Navigator nav = new Navigator(googleMap, latlng, latlng2); nav.findDirections(false, false); nav.setOnPathSetListener(new OnPathSetListener() {

@Override public void onPathSetListener(Directions directions) { // TODO Auto-generated method stub

}

I've implemented it up at the top of the class this is in and it autogenerated the methods but since I created a new listener I don't believe it is using it. It works though and not fooling with it. Learning new crap everyday. Thank you again.

tyczj commented 10 years ago

yes that is the other way of doing it. glad to hear it works

donaldhuebner commented 10 years ago

I noticed it does place the polyline all the way on the road exactly. Is there a way to get more lat long points to place the line closer on the road?

donaldhuebner commented 10 years ago

Traveling from on city to another seems to cause this it taking interstates.

tyczj commented 10 years ago

I am not sure I understand what you mean?

donaldhuebner commented 10 years ago

Sorry after reading back over that. The poly line it draws on the map does not closely match the road when traveling on interstates. It seems to get an array of latitude and longitude points which is spread out more than needed. Is there a way to bump up the amount of lat long points to make it follow the road better? I noticed if the location is close to the interstate it just pops the line over to the location and doesn't take the exit. I'm trying to calculate travel times and I know this will be wrong by it reporting this.

tyczj commented 10 years ago

I just parse what google returns to me so there is no way of adding more points or whatever. I never had a problem with the line not following turns on interstates or highways on anything I tested though. It might be just google does not have good data there?

donaldhuebner commented 10 years ago

Hmm.. okay. I wonder why the fragment is doing that.. If I query the same on a google application, like maps, the map looks fine. Thank you for all your help.

tyczj commented 10 years ago

What are the LatLng points you are using?

donaldhuebner commented 10 years ago

I thought maybe it was in walking mode, then I saw your default. Same even after forcing it. I'm using google autocomplete for 1904 McConnell Ave, evansville, in, united States to Walmart Supercenter, park plaza drive, Secaucus, NJ, united states. I geocode to get the lat lng and not sure how to see the numbers to give you an exact.

donaldhuebner commented 10 years ago

public void onClick(View v) { String value = autoCompView2.getText().toString();
List

addresses; //Get Long Lat of the Address try {
addresses = geocoder.getFromLocationName(value, 1); for(int i = 0; i < addresses.size(); i++) { // MULTIPLE MATCHES Address addr = addresses.get(i); double latitude = addr.getLatitude(); double longitude = addr.getLongitude(); // DO SOMETHING WITH VALUES //Setting a Destination longitude and latitude latlng2 = new LatLng(latitude, longitude); //Updating the Camera and Placing a Marker //googleMap.moveCamera(CameraUpdateFactory.newLatLng(latlng2)); //googleMap.animateCamera(CameraUpdateFactory.zoomTo(12)); //googleMap.addMarker(new MarkerOptions().position(latlng2)); Navigator nav = new Navigator(googleMap, latlng, latlng2);

                     nav.findDirections(true, true);
                     nav.setPathLineWidth(2);
                     nav.setOnPathSetListener(new OnPathSetListener() {

                @Override
                        public void onPathSetListener(Directions directions) {
                            googleMap.addMarker(new MarkerOptions().position(latlng2));

                        }
                    });
tyczj commented 10 years ago

you are right it does give weird directions with those coordinates for some reason, even If I use points I get by tapping on the map at those locations it does weird stuff. However if I tap on the map at other locations the route displays fine. I even tested cross state points and the showed fine...something must be weird with those points :/

donaldhuebner commented 10 years ago

Cool, glad I'm not the only one who sees it. I would appreciate it if you think of something and tell me. I'll do the same but I think I'm going to take my phone outside and wrap it in some C4. lol. Thanks man.

mg6maciej commented 10 years ago

Maybe the reason is the polyline is drawn based on overview_polyline / points and not all the steps / polyline / points?

tyczj commented 10 years ago

@mg6maciej If I use the steps polyline I only get a small segment of the path. Using the 2 points that @donaldhuebner gave me I only get 8 steps back from google

mg6maciej commented 10 years ago

How about concatenating all the points from all the steps of a single route?

mg6maciej commented 10 years ago

http://maps.googleapis.com/maps/api/directions/json?origin=1904%20McConnell%20Ave,%20evansville,%20in,%20united%20States&destination=Walmart%20Supercenter,%20park%20plaza%20drive,%20Secaucus,%20NJ,%20united%20states&sensor=false gives me more than 8 steps

tyczj commented 10 years ago

bah I found the problem, just pushed the update that fixes it

mg6maciej commented 10 years ago

Great. Glad I could help a bit.