2

好吧,我有 3 个人的纬度和经度,我需要获取并显示我的位置和其他 3 人之间的路线,如下所示:

在此处输入图像描述

我的应用程序中有一个带有 3 个联系人的小数据库,我的代码如下:

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();
}

}

并且只能显示这样的位置:

在此处输入图像描述

那么如何在驾驶模式下显示或显示我的位置和其他点之间的路线? 我看到任何示例或教程,但在某些示例中,库之间存在差异,例如:

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;

对于 ADT 或 Eclipse 和

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;

安卓工作室

还是 GeoPoint 相当于 LatLng?

或者我有什么错误或忘记了什么,我怎样才能将我的数据库中的 LatLng 对象放在一个数组中以显示路线?有什么帮助吗?多谢你们

4

2 回答 2

3

如果要显示两点之间的路线,则需要使用Google Directions API来检索 2 个位置之间的子点。

例如,您可以使用此 URL https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal以 JSON 格式获取多伦多和蒙特利尔之间的路线

获得这些点后,您只需使用map.addPolyline方法将它们放到地图上。

于 2015-01-06T14:15:34.750 回答
-2

你应该试试这个 行车路线路线

于 2014-07-09T14:45:59.410 回答