【问题标题】:Joining markers to draw path in android google map加入标记以在 android 谷歌地图中绘制路径
【发布时间】:2012-12-27 07:06:10
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    试试这个。

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

    希望对你有帮助

    【讨论】:

    • 我试过了..它工作正常..但我需要做的只是加入标记以显示通过加入线行进的路线..它自动显示行驶方向而不是我们经过仪式的路线??如果我错了,请纠正我..
    【解决方案2】:

    试试这个在谷歌地图中绘制路径

    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
    

    【讨论】:

    • 我试过了..它不适合我:(还有其他方法吗
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多