日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Android google map自定義的折現圖層的實現

系統 2081 0

?

實現結果如下:

?

? Android google map自定義的折現圖層的實現

?

?

代碼如下:?

    package com.easyway.polyline;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
/**
 * 自定義的折現圖層的實現
 *  在特定情況下,可能需要我們開發人員繪制特定的圖層在google map上面顯示
 *  
 *  
 * 
 * @author longgangbai
 *
 */
public class GooglePolylineActivity extends MapActivity {
	private MapView mapView;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mapView =(MapView)findViewById(R.id.mapView);
        
        //存儲連接的點的信息
        List<GeoPoint> points = new ArrayList<GeoPoint>();
        points.add(new GeoPoint(39907794,116356694));
        points.add(new GeoPoint(39950181,116415059));
        points.add(new GeoPoint(39909637,116435315));
        points.add(new GeoPoint(39902526,116398236));
        
        //添加自定義的圖層
        PolyLine polyline = new PolyLine(points);
        
        mapView.getOverlays().add(polyline); //map是MapView類型
        
        mapView.invalidate();
        mapView.setBuiltInZoomControls(true);
        
        MapController mapcontroller=mapView.getController();
        GeoPoint  point=new GeoPoint(39950181,116415059);
        mapcontroller.setCenter(point);
        mapcontroller.setZoom(7);
    }

    /**
     * 是否顯示路線顯示
     */
	@Override
	protected boolean isRouteDisplayed() {
		return true;
	}
	
	
}
  

?

?

?

    package com.easyway.polyline;


import java.util.List;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

/**
 * Goolge地圖之Polyline實現Overlay 以圖層形式存在.
 * MyLocationOverlay:定位當前位置的圖層
 * ItemizedOverlay:圖層的基類
 * OverlayItem:圖層的項
 * 
 * 
 * @author longgangbai
 */
public class PolyLine extends Overlay {
	List<GeoPoint> points;
	Paint paint;

	/**
	 * 構造函數,使用GeoPoint List構造Polyline
	 * 
	 * @param points
	 *            GeoPoint點List
	 */
	public PolyLine(List<GeoPoint> points) {
		this.points = points;
		paint = new Paint();
		paint.setColor(Color.BLUE);
		paint.setAlpha(150);
		paint.setAntiAlias(true);
		paint.setStyle(Paint.Style.FILL_AND_STROKE);
		paint.setStrokeWidth(4);
	}

	/**
	 * 使用GeoPoint點List和Paint對象來構造Polyline
	 * 
	 * @param points
	 *            GeoPoint點List,所有的拐點
	 * @param paint
	 *            Paint對象,用來控制劃線樣式
	 */
	public PolyLine(List<GeoPoint> points, Paint paint) {
		this.points = points;
		this.paint = paint;
	}


	/**
	 * 真正將線繪制出來 只需將線繪制到canvas上即可,主要是要轉換經緯度到屏幕坐標
	 */
	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		if (!shadow) {// 不是繪制shadow層
			Projection projection = mapView.getProjection();
			if (points != null) {
				if (points.size() >= 2) {
					Point start = projection.toPixels(points.get(0), null);// 需要轉換坐標
					for (int i = 1; i < points.size(); i++) {
						Point end = projection.toPixels(points.get(i), null);
						canvas.drawLine(start.x, start.y, end.x, end.y, paint);// 繪制到canvas上即可
						start = end;
					}
				}
			}
		}
	}
}
  

?

Android google map自定義的折現圖層的實現


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 德化县| 贵溪市| 惠来县| 温泉县| 加查县| 西藏| 探索| 镇原县| 泰州市| 千阳县| 西乌| 平江县| 建水县| 泉州市| 牡丹江市| 建宁县| 噶尔县| 宁津县| 长岭县| 凤冈县| 琼海市| 临江市| 鄢陵县| 名山县| 杭锦旗| 佳木斯市| 电白县| 蓝山县| 顺义区| 庆安县| 蓬莱市| 什邡市| 保山市| 新龙县| 波密县| 滕州市| 集安市| 四子王旗| 吉隆县| 烟台市| 稷山县|