2

well I have the latitude and longitude of 3 people, I need to get and display the route between my location and the other 3 like this:

enter image description here

I have a little data Base in my app with 3 contacts and my code is like:

package androiddatabase.app;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.Window;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;



/**
 * Created by Dennis and Rodrigo on 5/6/2014.
 */
public class RutasActivity extends FragmentActivity implements View.OnClickListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_ruta);

    GoogleMap mapa = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    mapa.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
    mapa.setMyLocationEnabled(true);
    mapa.getMyLocation();

    CargarContactos(this, mapa);

        //--------------------------------//
        //           GREETINGS            //
        //          FROM BOLIVIA!!!       //
        //              n_n               //
        //--------------------------------//
}

private  void  CargarContactos(Context context,GoogleMap mapa){
    myApp.DBManager manager = new myApp.DBManager(context);
    Cursor cursor = manager.CargarMapa();
    if (cursor.moveToFirst()) {
        do
        {
            if (cursor.getString(4).toString().contains("1")) {
                mapa.addMarker(new MarkerOptions()
                        .position(
                                new LatLng(Double.parseDouble(cursor.getString(2)),
                                        Double.parseDouble(cursor.getString(3)))
                        )
                        .title(cursor.getString(7) + " - " + cursor.getString(1))
                        .snippet("Fecha: " + cursor.getString(5) + " Monto: " + cursor.getString(6))
                        .icon(BitmapDescriptorFactory
                                .fromResource(R.drawable.familia)));
            }
            else
            {
                mapa.addMarker(new MarkerOptions()
                        .position(
                                new LatLng(Double.parseDouble(cursor.getString(2)),
                                        Double.parseDouble(cursor.getString(3)))
                        )
                        .title(cursor.getString(7) + " - " + cursor.getString(1))
                        .snippet("Fecha: " + cursor.getString(5) + " Monto: " + cursor.getString(6))
                        .icon(BitmapDescriptorFactory
                                .fromResource(R.drawable.amigos)));
            }
        }
        while(cursor.moveToNext());
    }

    cursor.close();
    manager.CloseManager();
}

}

and only can show the positions like this:

enter image description here

so how can I show or display the route in driving mode between my location and other points? I see any examples or tutorials but in someones examples exists differences between the libraries like:

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

for ADT or Eclipse and

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

for Android Studio

or GeoPoint is the equivalent to LatLng?

or am I wrong in something or forget something, how can I put my LatLng objects from my database in an array for show the route? any help? thanks Guys

user_Dennis_Mostajo
  • 2,279
  • 4
  • 28
  • 38
  • There is nothing in the Google Maps V2 SDK for driving directions. The other examples you are seeing are using Maps V1 (e.g., `com.google.android.maps.MapView`). Maps V1 also has nothing in it for driving directions, and Maps V1 was replaced by Maps V2. – CommonsWare May 06 '14 at 23:37
  • thanks @CommonsWare so Android Studio which version of Maps use? or you know any way to help me some tutorial, I did Try with polygons but I need show on the street way the route – user_Dennis_Mostajo May 06 '14 at 23:53
  • I think this old post is exactly what you need, please check it: http://stackoverflow.com/a/15053901/1468354 – Aboullaite May 07 '14 at 00:25
  • "which version of Maps use?" -- your only option is Maps V2. – CommonsWare May 07 '14 at 11:44
  • thanks @Aboullaite but show me a crash with the url for parsing xml – user_Dennis_Mostajo May 07 '14 at 15:33

2 Answers2

3

If you want to display route between two points, you need to use Google Directions API to retrieve sub points between 2 locations.

For example, you can get route between Toronto and Montreal as JSON with this url https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal

After getting these points you just have to put them onto map with map.addPolyline method.

Emre Koç
  • 1,343
  • 1
  • 25
  • 44
-2

You should try this Driving route directions

dilettante
  • 584
  • 6
  • 10