ios地图搜索开发,iOS地图开发

ios开发百度地图 怎么根据地址查询经纬度

(void)longPress:(UIGestureRecognizer*)gestureRecognizer {

创新互联主要从事做网站、网站设计、网页设计、企业做网站、公司建网站等业务。立足成都服务聂拉木,10多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18980820575

if (gestureRecognizer.state == UIGestureRecognizerStateBegan){ //这个状态判断很重要

//坐标转换

CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView];

CLLocationCoordinate2D touchMapCoordinate =

[self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];

//这里的touchMapCoordinate.latitude和touchMapCoordinate.longitude就是想要的经纬度,

NSLog(@"%f",touchMapCoordinate.latitude);

NSLog(@"%f",touchMapCoordinate.longitude);

//30.264998 120.122538 30.285012 120.117989

LocationObject *aLocationObject = [[LocationObject alloc]initWithTitle:@"hello" latitue:touchMapCoordinate.latitude longitude:touchMapCoordinate.longitude];

aLocationObject._subTitleString = @"world";

NSMutableArray *_mapAnnotations = [[NSMutableArray alloc]initWithCapacity:1];

[_mapAnnotations addObject:aLocationObject];

[self.mapView addAnnotations:_mapAnnotations ];

[_mapAnnotations release];

[aLocationObject release];

}

}

如何利用MapKit开发全英文检索的iOS地图

第一步:申请Key

先申请高德的KEY

1、填写应用名称

2、绑定服务选择IOS平台

3、输入bundle id:将Xcode切换到General标签,即可查看Bundle Identifier

4、点击获取KEY

第二步、新建地图工程

在xCode里,新建一个 Single View Application工程,并且进行配置。

在高德官网有地图配置的详细说明,这里我就不多说了。

第三步、添加MKMapView

1、在xCode里选择Build Phases标签,点开Link Binary With Libraries,再点加号。

2、在弹出来的搜索框里搜索Mapkit。

3、选择iOS 8.0--MapKit.framework,最后点击add即可。

第四步、申请定位权限

在 info.plist中追加NSLocationAlwaysUsageDescription或者NSLocationAlwaysUsageDescription字段。

NSLocationWhenInUseUsageDescription表示应用在前台的时候可以搜到更新的位置信息;NSLocationAlwaysUsageDescription表示应用在前台和后台(suspend或terminated)都可以获取到更新的位置数据。

所以我还是建议NSLocationAlwaysUsageDescription这种方便的模式,哈哈。

1.在工程的Supporting Files中选择plist文件

2.点击+号,输入字段NSLocationAlwaysUsageDescription

3.按回车,即可完成添加字段

第五步、初始化Mapview

高德的坐标系是国内标准坐标(GCJ-02,又称火星坐标),国际上一般是采用GPS坐标(WGS-84),所以大多数国际应用在中国使用时,需要进行坐标转换。

好在苹果的MapKit用的是高德的地图,showUserLocation= YES,坐标已经是GCJ-02的啦,可以直接使用~

(PS:不建议使用CLLocationManager定位管理类,它返回的坐标是GPS坐标,必须进行坐标转换,很麻烦。)

第六步、初始化AMapSearchAPI

构造AMapSearchAPI对象,设置搜索结果语言为英文AMapSearchLanguage_en。

这步非常重要喔!必须要设置成英文,才能巧妙地让POI搜索、逆地理编码和地理编码、输入提示等,都变成纯英文喔。

第七步、写个搜索demo来看看

以一个普通的POI检索为例,当检索英文关键词时,出来纯英文的搜素建议;搜索结果也用英文来展示。

/*  POI 搜索.  */

-  (void)searchPOIWithKey:(NSString *)key adcode:(NSString *)adcode

{

if (key.length == 0)

{

return;

}

//构造POI搜索对象AMapPlaceSearchRequest

AMapPlaceSearchRequest  *place = [[AMapPlaceSearchRequest alloc] init];

//设置关键字

place.keywords = key;

place.requireExtension = YES;//设置成YES,返回信息详细,较费流量

if (adcode.length 0)

{

place.city = @[adcode];

}

//发起查询

[_search  AMapPlaceSearch:place];

}

//回调中显示结果

-  (void)onPlaceSearchDone:(AMapPlaceSearchRequest *)request response:(AMapPlaceSearchResponse  *)respons

{

if (respons.pois.count == 0)

{

return;

}

NSMutableArray  *poiAnnotations = [NSMutableArray arrayWithCapacity:respons.pois.count];

[respons.pois  enumerateObjectsUsingBlock:^(AMapPOI *obj, NSUInteger idx, BOOL *stop) {

[poiAnnotations  addObject:[[POIAnnotation alloc] initWithPOI:obj]];

}];

/*  将结果以annotation的形式加载到地图上. */

[_mapView addAnnotations:poiAnnotations];

/*  如果只有一个结果,设置其为中心点. */

if (poiAnnotations.count == 1)

{

_mapView.centerCoordinate = [poiAnnotations[0] coordinate];

}

/* 如果有多个结果, 设置地图使所有的annotation都可见. */

else

{

[_mapView showAnnotations:poiAnnotations animated:NO];

}

}

iOS 一步一步实现百度地图范围搜索

效果图:

1.首先加载出百度地图

2.在地图加载成功后的方法里去得到左下角和右上角的坐标点的经纬度, 需要一个方法来实现屏幕坐标点转化成经纬度。

3.得到俩个点的经纬度就可以开始发起搜索了。

4.在搜索结果的代理方法里将搜索到的结果展示出来。

5.当地图区域发生改变时,会触发的方法有3个: "正在改变"、"即将改变"、"改变完成"。

很容易就想到,我们需要使用的是"改变完成"的方法,在里面重新请求一次搜索:

**

总结: demo只实现了一个很基础的功能,后期还可以增加更加炫酷的功能,比如改变气泡的形状。如果你有更好的想法,欢迎和我交流!

**

demo地址:

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

首先创建工程,并在工程Build PathConfigure Build Path…libraries 中选择“Add Externel JARs…”,选定

MapApi.jar,点击OK,这样就可以将高德地图Android API 库文件引入。然后在工程Build PathConfigure Build

Path…Order and Export 中将引入的库文件MapApi.jar 选中,点击OK,这样您就可以在您的程序中使用高德地图API

了。

二、我们在不熟悉的情况下、先尽量多的添加此软件应用权限;所以在mainifest中添加如下代码;插入的位置在

application的代码之前。

Java代码

uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/uses-permission

uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/uses-permission

uses-permission android:name="android.permission.INTERNET"/uses-permission

uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/uses-permission

uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/uses-permission

uses-permission android:name="android.permission.READ_PHONE_STATE"/uses-permission

uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/uses-permission

uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/uses-permission

三、接着就要在res文件下的layout中添加界面布局了。其代码如下、你可以完全复制进去。

Java代码

?xml version="1.0" encoding="utf-8"?

LinearLayout xmlns:android=""

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

!--添加文本输入框,查找地址--

LinearLayout

android:layout_height="wrap_content"

android:layout_width="wrap_content" android:orientation="horizontal"

xmlns:android=""

android:layout_gravity="center_horizontal"

TextView android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:text="经度"/

EditText android:layout_height="fill_parent"

android:layout_width="100px"

android:id="@+id/longitude"/

TextView android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:text="纬度"/

EditText android:layout_height="fill_parent"

android:layout_width="100px"

android:id="@+id/latitude"/

Button android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="查找"

android:id="@+id/button"/

/LinearLayout

com.amap.mapapi.map.MapView android:id="@+id/mapView"

android:layout_width="fill_parent" android:layout_height="fill_parent"

android: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

// 的控制权,可以用它控制和驱动平移和缩放

point = new GeoPoint((int) (39.982378 * 1E6), (int) (116.304923 * 1E6)); // 用给定的经纬度构造一个GeoPoint,单位是微度(度*

// 1E6)

// 按钮添加监听器

button_location = (Button) findViewById(R.id.location);

longitude = (EditText) findViewById(R.id.longitude);

latidute = (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 = latidute.getText().toString();

double lng = Integer.parseInt(lngStr);

//转成经纬度坐标

lat=lat*1E6;

lng=lng*1E6;

// 用给定的经纬度构造一个GeoPoint,单位是微度(度*1E6)

point = new GeoPoint((int) (lat), (int) (lng));

mMapController.setCenter(point); // 设置地图中心点

mMapController.setZoom(12); // 设置地图zoom 级别

// 添加地图覆盖物

// MyLocationOverlay(this, mMapView);

mylocTest.enableMyLocation(); // 判断是否发现位置提供者

mylocTest.enableCompass(); // 打开指南针

mMapView.getOverlays().add(mylocTest);// 添加定位覆盖物

}

}

};

// 按钮添加监听器

button_location.setOnClickListener(locationListener);

mMapController.setCenter(point); // 设置地图中心点

mMapController.setZoom(12); // 设置地图zoom 级别

// 添加地图覆盖物

mylocTest = new MyLocationOverlay(this, mMapView);

mylocTest.enableMyLocation(); // 判断是否发现位置提供者

mylocTest.enableCompass(); // 打开指南针

mMapView.getOverlays().add(mylocTest);// 添加定位覆盖物

}

//另外一个添加界面覆盖物的类:

public class MyLocationOverlayProxy extends com.amap.mapapi.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 LinkedListRunnable mRunOnFirstFix = new LinkedListRunnable();

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 point, long time) {

Projection pj=mapView.getProjection();

if (mLocation != null) {

mMapCoords=pj.toPixels(point, 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);

}

}

}

ios如何开发地图app

App内根据手机上装载的地图App将其显示在弹出的选择框,选择对应地图跳转进入地图导航。需要用到- (BOOL)canOpenURL:(NSURL *)url NS_AVAILABLE_IOS(3_0);方法判断手机是否已安装相应地图App。

要进行跳转需要先在xcode的plist文件内将目标App的url Scheme加入白名单(LSApplicationQueriesSchemes)。


网页名称:ios地图搜索开发,iOS地图开发
网站链接:http://ybzwz.com/article/dscocdh.html