24小时免费服务热线:15320418221

有谁知道iOS开发怎么能将根据地图搜索API搜索出来的地名直接标注在地图中心点上吗?

2021-09-23 17:33

花次元

花次元

德地图Android API 库文件引入。然后在工程Build Path>Configure Build Path…>Order and Export 中将引入的库文件MapApi.jar 选中,点击OK,这样您就可以在您的程序中使用地图API 了。
二、我们在不熟悉的情况下、先尽量多的添加此软件应用权限;所以在mainifest中添加如下代码;插入的位置在 <application的代码之前。 Java代码 <uses-permission :name=".permission.ACCESS_COARSE_LOCATION"></uses-permission> <uses-permission :name=".permission.ACCESS_FINE_LOCATION"></uses-permission> <uses-permission :name=".permission.INTERNET"></uses-permission> <uses-permission :name=".permission.ACCESS_NETWORK_STATE"></uses-permission> <uses-permission :name=".permission.WRITE_EXTERNAL_STORAGE"></uses-permission> <uses-permission :name=".permission.READ_PHONE_STATE"></uses-permission> <uses-permission :name=".permission.CHANGE_WIFI_STATE"></uses-permission> <uses-permission :name=".permission.ACCESS_WIFI_STATE"></uses-permission>
三、接着就要在res文件下的layout中添加界面布局了。其代码如下、你可以完全复制进去。 Java代码 <?xml version="
1.0" encoding="utf-8"?> <LinearLayout xmlns:="链接" :orientation="vertical" :layout_width="fill_parent" :layout_height="fill_parent" > <!--添加文本输入框,查找地址--> <LinearLayout :layout_height="wrap_content" :layout_width="wrap_content" :orientation="horizontal" xmlns:="链接" :layout_gravity="center_horizontal"> <TextView :layout_height="wrap_content" :layout_width="wrap_content" :text="经度"/> <EditText :layout_height="fill_parent" :layout_width="100px" :id="@+id/longitude"/> <TextView :layout_height="wrap_content" :layout_width="wrap_content" :text="纬度"/> <EditText :layout_height="fill_parent" :layout_width="100px" :id="@+id/latitude"/> <Button :layout_width="wrap_content" :layout_height="wrap_content" :text="查找" :id="@+id/button"/> </LinearLayout> <com.amap.map.map.MapView :id="@+id/mapView" :layout_width="fill_parent" :layout_height="fill_parent" :clickable="true" /> </LinearLayout>
四、最后就是软件的主程序部分了、里面需要的类和方法不多,主要以按钮的监听器和地图的界面实现为主 Java代码 public void onCreate(Bundle savedInstanceState) { // this.setMapMode(MAP_MODE_VECTOR);//设置地图为矢量模式 super.onCreate(savedInstanceState); setContentView(R.layout.main); mMapView = (MapView) findViewById(R.id.mapView); mMapView.setBuiltInZoomControls(true); // 设置启用内置的缩放控件 mMapController = mMapView.getController(); // 得到mMapView // 的控制权,可以用它控制和驱动平移和缩放 nt = new GeoPoint((int) (3
9.982378 * 1E6), (int) (11
6.304923 * 1E6)); // 用给定的经纬度构造一个GeoPoint,单位是微度(度* // 1E6) // 按钮添加监听器 button_location = (Button) findViewById(R.id.location); longitude = (EditText) findViewById(R.id.longitude); latite = (EditText) findViewById(R.id.latitude); locationListener = new OnClickListener() { public void onClick(View e) { if (e.equals(button_location)) { // 得到文本输入框的中经纬 度坐标值 String latStr = longitude.getText().toString(); // 将得到的字符串转成数值 double lat = Integer.parseInt(latStr); String lngStr = latite.getText().toString(); double lng = Integer.parseInt(lngStr); //转成经纬度坐标 lat=lat*1E6; lng=lng*1E6; // 用给定的经纬度构造一个GeoPoint,单位是微度(度*1E6) nt = new GeoPoint((int) (lat), (int) (lng)); mMapController.setCenter(nt); // 设置地图中心点 mMapController.setZoom(12); // 设置地图zoom 级别 // 添加地图覆盖物 // MyLocationOverlay(this, mMapView); mylocTest.enableMyLocation(); // 判断是否发现位置提供者 mylocTest.enableCompass(); // 打开指南针 mMapView.getOverlays().add(mylocTest);// 添加标注覆盖物 } } }; // 按钮添加监听器 button_location.setOnClickListener(locationListener); mMapController.setCenter(nt); // 设置地图中心点 mMapController.setZoom(12); // 设置地图zoom 级别 // 添加地图覆盖物 mylocTest = new MyLocationOverlay(this, mMapView); mylocTest.enableMyLocation(); // 判断是否发现位置提供者 mylocTest.enableCompass(); // 打开指南针 mMapView.getOverlays().add(mylocTest);// 添加标注覆盖物 } //另外一个添加界面覆盖物的类: public class MyLocationOverlayProxy extends com.amap.map.map.MyLocationOverlay{ private Location mLocation; protected final Paint mPaint = new Paint(); protected final Paint mCirclePaint = new Paint(); private Bitmap gps_marker=null; private Point mMapCoords = new Point(); private final float gps_marker_CENTER_X; private final float gps_marker_CENTER_Y; private final LinkedList<Runnable> mRunOnFirstFix = new LinkedList<Runnable>(); public MyLocationOverlayProxy(amap amap, MapView mMapView) { super(amap, mMapView); gps_marker = ((BitmapDrawable) amap.getResources().getDrawable( R.drawable.marker_gpsvalid)).getBitmap(); gps_marker_CENTER_X = gps_marker.getWidth() / 2 - 0.5f; gps_marker_CENTER_Y= gps_marker.getHeight() / 2 - 0.5f; } public boolean runOnFirstFix(final Runnable runnable) { if (mLocation != null) { new Thread(runnable).start(); return true; } else { mRunOnFirstFix.addLast(runnable); return false; } } public void onLocationChanged(Location location) { // TODO Auto-generated method stub mLocation = location; for(final Runnable runnable : mRunOnFirstFix) { new Thread(runnable).start(); } mRunOnFirstFix.clear(); super.onLocationChanged(location); } protected void drawMyLocation(Canvas canvas, MapView mapView, final Location mLocation, GeoPoint nt, long time) { Projection pj=mapView.getProjection(); if (mLocation != null) { mMapCoords=pj.toPixels(nt, null); final float radius = pj.metersToEquatorPixels(mLocation.getAccuracy()); this.mCirclePaint.setAntiAlias(true); this.mCirclePaint.setARGB(35, 131, 182, 222); this.mCirclePaint.setAlpha(50); this.mCirclePaint.setStyle(Style.FILL); canvas.drawCircle(mMapCoords.x, mMapCoords.y, radius, this.mCirclePaint); this.mCirclePaint.setARGB(225, 131, 182, 222); this.mCirclePaint.setAlpha(150); this.mCirclePaint.setStyle(Style.STROKE); canvas.drawCircle(mMapCoords.x, mMapCoords.y, radius, this.mCirclePaint); canvas.drawBitmap(gps_marker, mMapCoords.x-gps_marker_CENTER_X, mMapCoords.y-gps_marker_CENTER_Y, this.mPaint); } } }

2021-09-23 18:54:09

相关地图标注文章

相关地图标注热门问答

喵喵喵

知道经纬度怎么在地图上标注出来呢?

首先,你要知道怎么区分经纬度:南北纬:赤道以北为北纬(N);赤道以南为南纬(S)本初子午线(0度经线)以东为东经(E);本初子线以西为西经(W);再根据你所知道的经纬度来确定是南纬还是北纬,是东经还是西经,然后在地图上找到相应的数值,最终两条数值交叉的地方就是要标注的位置

2021-09-23 17:26:00

柔情心扉

有谁知道iOS开发怎么能将根据地图搜索API搜索出来的地名直接标注在地图中心点上吗?

德地图Android API 库文件引入。然后在工程Build Path>Configure Build Path…>Order and Export 中将引入的库文件MapApi.jar 选中,点击OK,这样您就可以在您的程序中使用地图API 了。 二、我们在不...

2021-09-23 17:33:54

槐树's dreamer

请问有谁知道地图怎么标注吗??

找地图标注公司标注,联系广州【启来】鐧惧害鍦板浘

2021-09-23 17:44:30

young program

地图开发(公司)有谁知道呀?

随着电子地图被越来越多的人所熟知和使用,市场上专门从事电子地图的开发公司也越来越多,特别是上海、北京、广州等一线城市,这类公司更加多。像北京超图、上海为卓、广州哈图等,都是其中比较出名的电子地图开发公司。

2022-04-06 11:55:01