好吧,我是一個在android的begginer,我需要使用設備上的地圖更具體(多段線)我需要做這樣的事情。 Android多段線地圖api
這是一個網絡應用程序,我跟蹤了我的城市的巴士路線和巴士站,並且我被要求在android上做同樣的事情!我一直在檢查Android的地圖API,並沒有發現類似於JS API中的折線,有沒有辦法做到這一點?
我沒有問題添加簡單的覆蓋物我一直在檢查android開發人員網站的基本教程,但我不知道如何繪製折線。
好吧,我是一個在android的begginer,我需要使用設備上的地圖更具體(多段線)我需要做這樣的事情。 Android多段線地圖api
這是一個網絡應用程序,我跟蹤了我的城市的巴士路線和巴士站,並且我被要求在android上做同樣的事情!我一直在檢查Android的地圖API,並沒有發現類似於JS API中的折線,有沒有辦法做到這一點?
我沒有問題添加簡單的覆蓋物我一直在檢查android開發人員網站的基本教程,但我不知道如何繪製折線。
Android谷歌地圖API中沒有這樣的API。您只能首先列出要繪製的路線的實際GeoPoint,然後在Overlay對象上繪製點和線。有沒有簡單的方法來做到這一點。
更簡單的方法是獲取您的觀點並擴展ImageView,以顯示您的圖像以繪製點,而您只需要傳遞要繪製的點。
在我的項目我做:
public class ImageDraw extends ImageView{
private Paint mPaint = new Paint();
List<Point> pts = new ArrayList<Point>() ;
public ImageDraw(Context context) {
super(context);
}
//used to send the location of the points to draw on the screen
//must be called before every redraw to update the points on the screen
public void SetPointsToDraw(List<Point> pts)
{
this.pts = pts;
}
public ImageDraw(Context context, AttributeSet attrs)
{
super(context,attrs);
}
public ImageDraw(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
}
@Override
public void onDraw(Canvas canvas)
{
super.onDraw(canvas);
Paint paintColor = mPaint;
paintColor.setColor(Color.YELLOW);
paintColor.setStrokeWidth(3);
if(pts.size() > 0)
{
canvas.drawCircle(pts.get(0).x, pts.get(0).y, 7, paintColor);
}
if (pts.size() > 1)
{
for (int i = 1 ; i < pts.size(); i++) {
paintColor.setColor(Color.YELLOW);
canvas.drawCircle(pts.get(i).x, pts.get(i).y, 7, paintColor);
paintColor.setColor(Color.RED);
canvas.drawLine(pts.get(i-1).x, pts.get(i-1).y, pts.get(i).x, pts.get(i).y, paintColor);
}
}
}
}
當你擴展了ImageView的,並使用XML不`噸佈局忘記把你的整套新的小部件,如: com.Myapp.MyImageView
FVZ的答案的作品,但不是原生的方式,也有地圖,一個簡單的例子 https://stackoverflow.com/a/21877742/618419
上折線另外看看Android文檔,他們有很多簡單而且很好的拼裝示例: http://developer.android.com/reference/com/google/android/gms/maps/model/Polyline.html
真的嗎?就像那樣?生病檢查出來!非常感謝! – Gustavo 2011-04-14 22:13:22