0

我是android领域的新手。我编写了一个android App1,它将从 Network Provider 检索纬度和经度值并将其存储在我的本地服务器(LAMP)中。

我还创建了一个MYSQL DB包含 3 列(lat、lon、id)的表,其中包含使用网络提供程序检索的值(lat 和 lon)。目前我的表中有多个10值。

我创建了对象,用于在我的Android App2中使用 PHP 脚本JSON获取这些值。所有这些事情都很好。我还完成了创建 ,它将使用标记在地图上绘制这些纬度和经度值。MYSQL DBMapActivity

我现在要做的是加入这些标记以在谷歌地图上绘制路径。怎么做。请帮忙

4

2 回答 2

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

这可以帮助你吗

于 2012-12-27T07:16:03.940 回答
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
于 2012-12-27T07:39:11.237 回答