【发布时间】:2014-06-23 17:37:49
【问题描述】:
好吧,我有 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;
适用于 Android Studio
或 GeoPoint 是否等同于 LatLng?
或者我有什么错误或忘记了什么,我如何将我的 LatLng 对象从我的数据库中放入一个数组中以显示路线?有什么帮助吗?谢谢各位
【问题讨论】:
-
Google Maps V2 SDK 中没有用于行车路线的任何内容。您看到的其他示例正在使用 Maps V1(例如,
com.google.android.maps.MapView)。 Maps V1 也没有任何行车路线,Maps V1 被 Maps V2 取代。 -
感谢@CommonsWare 那么Android Studio 使用哪个版本的地图?或者你知道有什么方法可以帮助我一些教程,我确实尝试过多边形,但我需要在街道上展示路线
-
我觉得这篇旧帖正是你需要的,请查收:stackoverflow.com/a/15053901/1468354
-
"使用哪个版本的地图?" -- 您唯一的选择是 Maps V2。
-
感谢@Aboullaite,但告诉我解析 xml 的 url 崩溃
标签: android google-maps android-studio google-maps-api-2 driving-directions