Phát triển ứng dụng cho iPhone và iPad - part 37

Tham khảo tài liệu 'phát triển ứng dụng cho iphone và ipad - part 37', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Example 1 Location-Based Search 329 Next you define an MKCoordinateRegion struct. You will pass this struct to the mapView to define the region that you want to display. An MKCoordinateRegion consists of a span and a center point. You will center the map on the coordinate that you receive from Core Location. Next you tell the mapView to set the region displayed on the map and to animate the transition to your new region. Finally you tell the Core Location manager to stop getting location updates from the GPS. Because your application does not need extremely accurate resolution nor do you need constant updates from the GPS you can conserve power by turning the GPS off. For the next step you need to make a couple of additions to the viewDidLoad method. Because you will be customizing the pin colors for your annotations you need to set the mapView delegate to self. In addition for illustrative purposes you will display the user s location on the map by setting the map view s showsUserLocation property to YES. When using the showsUserLocation property you need to be aware that this will cause the map view to use Core Location to retrieve and maintain the user s location on the map. This forces the GPS receiver to remain on consuming valuable battery power. You should carefully consider if your application needs this functionality or not before using it. This example uses this feature to demonstrate a capability of the map view to display the user s current location. Here is the complete implementation of viewDidLoad O- void viewDidLoad super viewDidLoad Available lor download on Create the results array NSMutableArray alloc init Create the Core Location CLLocationManager CLLocationManager locationManager CLLocationManager alloc init Set the delegate to self locationManager setDelegate self Tell the location manager to start updating the location locationManager startUpdatingLocation Set the delegate for the searchbar setDelegate .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.