1

I'm a new Android Developer and I have been researching on this topic for over 2 weeks before resorting to asking this question on SO. A lot of the code I've found that does routing are all in KML which is not supported anymore.

I'd be most grateful if someone could provide me examples or working code to go about doing this and please note that I am a beginner android developer.

Thank you so much.

neocoolstar
  • 63
  • 1
  • 6

1 Answers1

0

You can see my post here, it shows you how to get Directions from JSON instead of KML since it is not supported anymore.

Community
  • 1
  • 1
Hesham Saeed
  • 5,358
  • 7
  • 37
  • 57
  • Thank you so much for your response. I'll look into your code. – neocoolstar Sep 01 '12 at 14:14
  • Having problems implementing your code. The program won't run on the AVD. This is part of what I get in the log cat `E/AndroidRuntime(893): FATAL EXCEPTION: main E/AndroidRuntime(893): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemaps/com.example.googlemaps.MainActivity}: java.lang.NullPointerException E/AndroidRuntime(893): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059) E/AndroidRuntime(893): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)` – neocoolstar Sep 03 '12 at 09:07
  • You didn't paste the whole error, there is some place where it is written that this NullPointerException "caused by:", paste from caused by until the end of the error. – Hesham Saeed Sep 03 '12 at 10:29
  • OK I fixed that and am now getting a 'NetworkOnMainThreadException' I read your response to another person who got the same error, but I didn't quite understand what to do. – neocoolstar Sep 03 '12 at 10:43
  • Yes, you are getting the JSON directions on the Main Thread, which is wrong, you will have to use AsyncTask and put the code which you are querying the direction inside `doInBackground()` method, you can search for tutorials about AsyncTask. – Hesham Saeed Sep 03 '12 at 12:04
  • So should I move directions() to another class and extend AsyncTask? – neocoolstar Sep 04 '12 at 03:05
  • Yes, and in the original place of `directions()` you will execute this AsyncTask there. – Hesham Saeed Sep 04 '12 at 04:47