Captain Chod
Captain Chod

Reputation: 67

Android Maps KML Handler

Ok so at the moment I'm getting a null pointer exception when adding to the list of overlays. I've declared this at the top of the map activity class:

private static List<Overlay> mOverlays;

And then further down I've got this for my source/ from point:

Drawable fromDrawable = getResources().getDrawable(R.drawable.pin_blue);
OverlayItem fromOverlayItem = new OverlayItem(fromGeoPoint, "Hello!", "This is your current Location.");
MapWhatsNearOverlay fromItemizedOverlay = new MapWhatsNearOverlay(fromDrawable);
mOverlays.add(fromItemizedOverlay);

connectAsyncTask _connectAsyncTask = new connectAsyncTask();
_connectAsyncTask.execute();
mMapView.getOverlays().add((Overlay) mOverlays);

And the same for the destination as well, but the null pointer exception pops up when processing the bottom line of code.

Upvotes: 0

Views: 541

Answers (1)

Shankar Agarwal
Shankar Agarwal

Reputation: 34765

Refer this link to draw driving path in your application. You just need to add the four classes present in the link in your project and call the below lines when you need to display the route.

SharedData data = SharedData.getInstance();
data.setAPIKEY("0RUTLH7cqd6yrZ0FdS0NfQMO3lioiCbnH-BpNQQ");//set your map key here
data.setSrc_lat(17);//set your src lat
data.setSrc_lng(78);//set your src lng
data.setDest_lat(18);//set your dest lat
data.setDest_lng(77);//set your dest lng
startActivity(new Intent(YourActivity.this,RoutePath.class));//add RoutePath in your manifeast file

//Also add the permission to your manifeast file

Upvotes: 1

Related Questions