我是android领域的新手。我编写了一个 android App1 ,它将从网络提供程序中检索纬度和经度值,并将其存储在我的本地服务器(LAMP)
中。
我还创建了一个MYSQL DB
表,其中包含3列(lat,lon,id),其中包含使用网络提供程序检索的值(lat和lon)。目前,我的表中有超过10
个值。
我创建了JSON
对象,用于在我的 Android App2 中使用PHP脚本从MYSQL DB
获取这些值。所有这些都很好。我还创建了MapActivity
,它将使用Marker在地图上绘制那些lat和lon值。
我现在要做的是加入这些标记以在谷歌地图上绘制路径。怎么做。请帮忙
答案 0 :(得分:3)
试试这个。
String uri = "http://maps.google.com/maps?saddr=" + currentLatitude+","+currentLongitude+"&daddr="+fixedLatitude+","+fixedLongitude;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
这可以帮到你
答案 1 :(得分:1)
试试这个在谷歌地图中绘制路径
public class Location extends MapActivity {
MapView mapView;
public static ArrayList<String> paramLat = new ArrayList<String>();
public static ArrayList<String> paramLong = new ArrayList<String>();
private List<Overlay> mapOverlays;
public List<GeoPoint> geopoints = new ArrayList<GeoPoint>();
public void onCreate(Bundle savedInstanceState) {
//your code to display location
for(int i=0;i<paramLat.size();i++)
{
lat = Double.parseDouble(paramLat.get(i));
lon = Double.parseDouble(paramLong.get(i));
geoPoint = new GeoPoint((int)(lat * 1E6), (int)(lon *1E6));
geopoints.add(geoPoint);
}
mapOverlays = mapView.getOverlays();
mapOverlays.add(new MyOverlay());
}
class MyOverlay extends Overlay{
public MyOverlay(){
}
public void draw(Canvas canvas, MapView mapv, boolean shadow){
super.draw(canvas, mapv, shadow);
int loopcount = geopoints.size() - 1;
Paint mPaint = new Paint();
mPaint.setDither(true);
mPaint.setColor(Color.BLUE);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(2);
for (int i = 0; i < loopcount; i++)
{
GeoPoint pp1 = (GeoPoint) geopoints.get(i);
GeoPoint pp2 = (GeoPoint) geopoints.get(i + 1);
Point p1 = new Point();
Point p2 = new Point();
Path path = new Path();
projection.toPixels(pp1, p1);
projection.toPixels(pp2, p2);
path.moveTo(p2.x, p2.y);
path.lineTo(p1.x,p1.y);
canvas.drawPath(path, mPaint);
}
}
} //end of MyOverlay class
} //end of Location class