0

My Problem is I have 4 Location's Latitude and Longitude into my local database, I am fetching those data and use for draw route path in android but problem is first to second location route is not display on mapview other second to third and third to fourth route path is display on mapview. Sorry for bad English communication.

i am getting code from following link for draw route path.

MapRoute Example

and call drawing class using following function:-

public void drawpath(){
        mDb.open();
        Cursor cr = mDb.getAllTitles();
        cr.moveToFirst();

        if (cr.getCount() > 0) {
            for (int i = 0; i <= cr.getCount()/2; i++) {
                fromlat = Double.parseDouble(cr.getString(1));
                fromlng = Double.parseDouble(cr.getString(2));
                cr.moveToNext();
                tolat = Double.parseDouble(cr.getString(1));
                tolng = Double.parseDouble(cr.getString(2));

                String url = RoadProvider
                        .getUrl(fromlat, fromlng, tolat, tolng);
                InputStream is = getConnection(url);
                mRoad = RoadProvider.getRoute(is);
                MapOverlay mapOverlay = new MapOverlay(mRoad, mapView);
                List<Overlay> listOfOverlays = mapView.getOverlays();
                listOfOverlays.add(mapOverlay);
                mapView.invalidate();
            }
        }

        cr.close();
        mDb.close();
    }
Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128

2 Answers2

0
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);
Ramesh Solanki
  • 2,961
  • 4
  • 28
  • 44
0

It is happening because you are using cr.getCount()/2.

When you will have even number of count then it will work not work fine

For example if you have 4 number of rows then you cr.getCount()/2 = 2 so your loop will continue from 0 to 2 means 3 times. Actually it should be continue 2 times as your coding.

Now lat take a odd numbers say 5 so cr.getCount()/2 = 2 because i is the integer value so your loop will work total 3 times.

So you have different mechanism.

Like try to add all the lat and long in the arraylist and then after loop complete.

Make a loop of the size of that arrayList and create a path.May be for that you required two additional variable to store the previous lat and long.

Dharmendra
  • 33,296
  • 22
  • 86
  • 129