国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Android 地圖開發(fā),高德地圖,兩點(diǎn)畫線或者多點(diǎn) 畫線

2023-07-05 04:46 作者:翼618  | 我要投稿

最近用高德地圖做一些繪制行走路線的功能,帖子寫的都好模糊,

我這里整個最簡單的


先上效果圖,只看地圖部分即可,地圖高度寬度可以修改的

效果圖

下面是具體代碼


首先還是最簡單的布局文件

? ? <com.amap.api.maps.MapView

? ? ? ? android:layout_marginTop="10dp"

? ? ? ? android:id="@+id/map"

? ? ? ? android:layout_width="match_parent"

? ? ? ? android:layout_height="150dp"/>


然后是代碼部分


--------我是分割線----------------------------------------------

//聲明一個外部變量

MapView mapView;

/**

?* protected void onCreate(Bundle savedInstanceState) {

?* 參數(shù)就是這玩意 savedInstanceState

?*然后直接調(diào)用這個方法就好

?*/

? ? private void setMap(Bundle savedInstanceState){


? ? ? ? mapView = (MapView) findViewById(R.id.map);

? ? ? ? //必須

? ? ? ? mapView.onCreate(savedInstanceState);

? ? ? ? AMap aMap = mapView.getMap();

? ? ? ? List<LatLng> latLngList = getLatLngList();

? ? ? ? //移動相機(jī)到中心點(diǎn),第二個參數(shù)是相機(jī)縮放倍數(shù)

? ? ? ? aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLngList.get(0), 18));


? ? ? ? //畫線 具體參數(shù)可以在這里修改

? ? ? ? aMap.addPolyline(new PolylineOptions()

? ? ? ? ? ? ? ? .addAll(latLngList)//添加一個LatLng列表

? ? ? ? ? ? ? ? .color(Color.RED)//線條的顏色

? ? ? ? ? ? ? ? .width(10f)//線條的寬度

? ? ? ? ? ? ? ? .setDottedLine(false)//點(diǎn)線?虛線?

? ? ? ? );


? ? }


//這個是設(shè)置具體的路徑參數(shù),可以設(shè)置復(fù)數(shù)多個

? ? private List<LatLng> getLatLngList() {

? ? ? ? List<LatLng> latLngList = new ArrayList<>();

? ? ? ? /*

? ? ? ? ?*/ 有幾個點(diǎn) 線就會跟著繞? ?2個也行 M個也行

? ? ? ? ?*/

? ? ? ? latLngList.add(new LatLng(23.11538, 113.395984));

? ? ? ? latLngList.add(new LatLng(23.11538, 113.395004));

? ? ? ? latLngList.add(new LatLng(23.11508, 113.395004));

? ? ? ? return latLngList;

? ? }


--------我是分割線----------------------------------------------

這里附上一個拓展方法就是設(shè)置一個?提示語 沒需要可以無視這個

用法是直接靠過去,把a(bǔ)Map對應(yīng)上就好



? ? ?//帶自定義文本的Marker標(biāo)記

? ? ? ? Bitmap bitmap = setCanvasTitle("起始位置");//設(shè)置提示語的圖片

? ? ? ? aMap.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(bitmap))

? ? ? ? ? ? ? ? .position(latLngList.get(0)));


? ? ? ? Bitmap bitmap1 = setCanvasTitle( "結(jié)束位置");//設(shè)置提示語的圖片

? ? ? ? aMap.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(bitmap1))

? ? ? ? ? ? ? ? .position(latLngList.get(2)));



? ? /**

? ? ?* 設(shè)置坐標(biāo)的提示語 和小圖標(biāo)? bitmap

? ? ?*/

? ? private Bitmap setCanvasTitle(String s) {

? ? ? ? Bitmap bitmap = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE).getBitmap();

? ? ? ? bitmap = imageScale(bitmap, 150, 150);//調(diào)整圖片的大小

? ? ? ? Canvas canvas = new Canvas(bitmap);

? ? ? ? Paint paint = new Paint();

? ? ? ? paint.setColor(Color.WHITE);

? ? ? ? paint.setTextAlign(Paint.Align.CENTER);

? ? ? ? paint.setTextSize(25f);

? ? ? ? paint.setTypeface(Typeface.DEFAULT_BOLD);

? ? ? ? canvas.drawText(s, bitmap.getWidth() / 2, bitmap.getHeight() / 2, paint);

? ? ? ? return? bitmap;

? ? }

--------我是分割線----------------------------------------------



Android 地圖開發(fā),高德地圖,兩點(diǎn)畫線或者多點(diǎn) 畫線的評論 (共 條)

分享到微博請遵守國家法律
贵德县| 文昌市| 潮州市| 隆子县| 郎溪县| 岳西县| 蒙城县| 乌海市| 巍山| 汕头市| 栾川县| 南汇区| 抚宁县| 龙陵县| 周口市| 凌源市| 吉隆县| 共和县| 邮箱| 绥宁县| 宁武县| 炉霍县| 和龙市| 玉树县| 顺义区| 琼结县| 阿城市| 通州市| 宝兴县| 突泉县| 冷水江市| 页游| 平度市| 马尔康县| 饶河县| 北宁市| 商丘市| 武隆县| 乌兰县| 来宾市| 亚东县|