간단한 큰 바늘 지도 표시 연습(xib 없음)
7353 단어 지도.
다음은 추가된 코드입니다
mapView.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import <QuartzCore/QuartzCore.h>
@interface mapView : UIViewController <CLLocationManagerDelegate>
{
CLLocationManager *locManager;
MKMapView *map;
CLLocation *bestLocation;
}
@property (retain) CLLocationManager *locManager;
@property (retain) CLLocation *bestLocation;
@end
mapView.m
//
// mapView.m
// Map
//
// Created by SuperHappy on 12-1-31.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "mapView.h"
#define BARBUTTON(TITLE, SELECTOR) [[[UIBarButtonItem alloc] initWithTitle:TITLE style:UIBarButtonItemStylePlain target:self action:SELECTOR] autorelease]
@implementation mapView
@synthesize locManager;
@synthesize bestLocation;
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"Location manager error :%@",[error description]);
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
if (!self.bestLocation) {
self.bestLocation = newLocation;
}
else if(newLocation.horizontalAccuracy < bestLocation.horizontalAccuracy)
self.bestLocation = newLocation;
map.region = MKCoordinateRegionMake(self.bestLocation.coordinate, MKCoordinateSpanMake(0.1f, 0.1f));
map.showsUserLocation = YES;
map.zoomEnabled = NO;
}
- (void)findme
{
// disable right button
self.navigationItem.rightBarButtonItem = nil;
// Search for the best location
self.bestLocation = nil;
self.locManager.delegate = self;
[self.locManager startUpdatingLocation];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
[super loadView];
map = [[MKMapView alloc]initWithFrame:CGRectMake(10, 10, 300, 300)];
[self.view addSubview:map];
[map release];
self.navigationController.navigationBar.tintColor = [UIColor redColor];
self.locManager = [[[CLLocationManager alloc] init] autorelease];
if (!self.locManager.locationServicesEnabled)
{
NSLog(@"User has opted out of location services");
return;
}
else
{
// User generally allows location calls
self.locManager.desiredAccuracy = kCLLocationAccuracyBest;
self.navigationItem.rightBarButtonItem = BARBUTTON(@"Find Me", @selector(findme));
}
}
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
도쿄도 건축물 환경 계획서의 데이터로 물건 사이트를 만들어 봤어요.나는 원래 이 집을 좋아했지만 도쿄도 건축물 환경계획서의 데이터가 좋아서 그것을 바탕으로 이 사이트를 만들었다. 이 물건의 구조물의 규격정보, 지도정보, 거주편안정보를 조합하여 감각이 좋은 물건 사이트를 만들고 싶다...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.