欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS開發(fā)之離線地圖核心代碼

 更新時間:2016年04月19日 09:52:20   作者:Livia.Chen  
本文給大家分享ios開發(fā)之離線地圖核心代碼,代碼簡單易懂,非常實用,有需要的朋友參考下

一,效果圖。


二,工程圖。


三,代碼。

ViewController.h

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import "MapLocation.h"
@interface ViewController : UIViewController
<MKMapViewDelegate>
{
  MKMapView *_mapView;
  NSString *addressString;
}
@end 

ViewController.m

 #import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view.
  //調(diào)用系統(tǒng)自帶的高德地圖
  //顯示當(dāng)前某地的離線地圖
  _mapView = [[MKMapView alloc] init];
  _mapView.frame = CGRectMake(0, 40, 320,400);
  _mapView.delegate = self;
  _mapView.mapType = MKMapTypeStandard;
  [self.view addSubview:_mapView];
  addressString=@"光啟城";
  NSLog(@"---addressString---%@",addressString);
  [self geocodeQuery];
}
- (void)geocodeQuery{
  if (addressString == nil || [addressString length] == 0) {
    return;
  }
  CLGeocoder *geocoder = [[CLGeocoder alloc] init];
  [geocoder geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *error) {
    NSLog(@"查詢記錄數(shù):%ld",[placemarks count]);
    if ([placemarks count] > 0) {
      [_mapView removeAnnotations:_mapView.annotations];
    }
    for (int i = 0; i < [placemarks count]; i++) {
      CLPlacemark* placemark = placemarks[i];
      //調(diào)整地圖位置和縮放比例
      MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(placemark.location.coordinate, 10000, 10000);
      [_mapView setRegion:viewRegion animated:YES];
      MapLocation *annotation = [[MapLocation alloc] init];
      annotation.streetAddress = placemark.thoroughfare;
      annotation.city = placemark.locality;
      annotation.state = placemark.administrativeArea;
      annotation.zip = placemark.postalCode;
      annotation.coordinate = placemark.location.coordinate;
      [_mapView addAnnotation:annotation];
    }
  }];
}
#pragma mark Map View Delegate Methods
- (MKAnnotationView *) mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>) annotation {
  MKPinAnnotationView *annotationView
  = (MKPinAnnotationView *)[_mapView dequeueReusableAnnotationViewWithIdentifier:@"PIN_ANNOTATION"];
  if(annotationView == nil) {
    annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation
                             reuseIdentifier:@"PIN_ANNOTATION"];
  }
  annotationView.pinColor = MKPinAnnotationColorPurple;
  annotationView.animatesDrop = YES;
  annotationView.canShowCallout = YES;
  return annotationView;
}
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
  _mapView.centerCoordinate = userLocation.location.coordinate;
}
- (void)mapViewDidFailLoadingMap:(MKMapView *)theMapView withError:(NSError *)error {
  NSLog(@"error : %@",[error description]);
}
@end 

MapLocation.h

#import <MapKit/MapKit.h>
@interface MapLocation : NSObject<MKAnnotation>
//街道信息屬性
@property (nonatomic, copy) NSString *streetAddress;
//城市信息屬性
@property (nonatomic, copy) NSString *city;
//州、省、市信息
@property (nonatomic, copy) NSString *state;
//郵編
@property (nonatomic, copy) NSString *zip;
//地理坐標(biāo)
@property (nonatomic, readwrite) CLLocationCoordinate2D coordinate;
@end 

 MapLocation.m

//地圖調(diào)用函數(shù)
#import "MapLocation.h"
@implementation MapLocation
- (NSString *)title {
  return @"您的位置!";
}
- (NSString *)subtitle {
  NSMutableString *ret = [NSMutableString new];
  if (_state)
    [ret appendString:_state];
  if (_city)
    [ret appendString:_city];
  if (_city && _state)
    [ret appendString:@", "];
  if (_streetAddress && (_city || _state || _zip))
    [ret appendString:@" • "];
  if (_streetAddress)
    [ret appendString:_streetAddress];
  if (_zip)
    [ret appendFormat:@", %@", _zip];
  return ret;
}
@end

相關(guān)文章

  • IOS實現(xiàn)展開二級列表效果

    IOS實現(xiàn)展開二級列表效果

    本文通過實例代碼向大家演示在IOS中如何實現(xiàn)展開二級列表的效果,這個功能效果很好,對于日常開發(fā)APP中很有幫助,下面一起來看看如何實現(xiàn)吧。
    2016-08-08
  • iOS實現(xiàn)文件下載功能

    iOS實現(xiàn)文件下載功能

    這篇文章主要為大家詳細(xì)介紹了iOS實現(xiàn)文件下載功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • iOS開發(fā)之觸摸事件以及手勢

    iOS開發(fā)之觸摸事件以及手勢

    這篇文章主要為大家詳細(xì)介紹了iOS開發(fā)之觸摸事件以及手勢的相關(guān)資料,感興趣的小伙伴們可以參考一下
    2016-04-04
  • IOS百度地圖導(dǎo)航開發(fā)功能實現(xiàn)簡述

    IOS百度地圖導(dǎo)航開發(fā)功能實現(xiàn)簡述

    百度地圖導(dǎo)航非常實用,那么基于代碼是如何實現(xiàn)的呢,下面通過本文給大家介紹IOS百度地圖導(dǎo)航開發(fā)功能實現(xiàn)簡述,需要的朋友可以參考下本文
    2016-03-03
  • ios彈幕高效加載實現(xiàn)方式實例代碼

    ios彈幕高效加載實現(xiàn)方式實例代碼

    看到密密麻麻的彈幕第一印象就是怎么樣高效加載來避免卡頓,這篇文章主要介紹了ios彈幕高效加載實現(xiàn)方式實例代碼,有興趣的可以了解一下。
    2017-03-03
  • 阿里數(shù)據(jù)iOS端啟動速度優(yōu)化心得

    阿里數(shù)據(jù)iOS端啟動速度優(yōu)化心得

    本篇文章給大家詳細(xì)分析了阿里數(shù)據(jù)iOS端啟動速度優(yōu)化的知識點(diǎn)以及心得,對此有興趣的朋友參考學(xué)習(xí)下吧。
    2018-02-02
  • iOS10 App適配權(quán)限 Push Notifications 字體Frame 遇到的問題

    iOS10 App適配權(quán)限 Push Notifications 字體Frame 遇到的問題

    這篇文章主要介紹了iOS10 App適配權(quán)限 Push Notifications 字體Frame 遇到的問題,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-09-09
  • ios電子書翻頁效果代碼詳解

    ios電子書翻頁效果代碼詳解

    這篇文章主要介紹了ios電子書翻頁效果代碼實現(xiàn)過程以及對應(yīng)的代碼講解,有需要的朋友參考下。
    2018-02-02
  • ios開發(fā)Flutter之?dāng)?shù)據(jù)存儲

    ios開發(fā)Flutter之?dāng)?shù)據(jù)存儲

    這篇文章主要為大家介紹了ios開發(fā)Flutter之?dāng)?shù)據(jù)存儲的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-07-07
  • iOS開發(fā)常用線程安全鎖

    iOS開發(fā)常用線程安全鎖

    這篇文章主要為大家介紹了iOS開發(fā)常用線程安全鎖示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-07-07

最新評論