我希望在地图上显示十大板球场地。
在我的代码中,我只获得了一个位置,即模拟器的默认经度和纬度值。
如何显示多个位置?
·H
#import <MapKit/MapKit.h>
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController<CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
CLLocation *currentLocation;
IBOutlet UILabel *label1;
IBOutlet UILabel *lable2;
}
@property (weak, nonatomic) IBOutlet MKMapView *myMapview;
@property (weak, nonatomic) IBOutlet UILabel *label2;
@property (weak, nonatomic) IBOutlet UILabel *lable1;
@end
的.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
_myMapview.showsUserLocation = YES;
[self->locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
//NSLog(@”dLatitude : %@”, latitude);
//NSLog(@”dLongitude : %@”,longitude);
NSLog(@"MY HOME :%@", latitude);
NSLog(@"MY HOME: %@ ", longitude);
}
#pragma mark CLLocationManager Delegate
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
currentLocation = [locations objectAtIndex:0];
[locationManager stopUpdatingLocation];
[self->locationManager stopUpdatingLocation];
NSLog(@"my latitude :%f",currentLocation.coordinate.latitude);
NSLog(@"my longitude :%f",currentLocation.coordinate.longitude);
label1.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
lable2.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
NSLog(@"Detected Location : %f, %f", currentLocation.coordinate.latitude, currentLocation.coordinate.longitude);
CLGeocoder *geocoder = [[CLGeocoder alloc] init] ;
[geocoder reverseGeocodeLocation:currentLocation
completionHandler:^(NSArray *placemarks, NSError *error)
{
if (error)
{
NSLog(@"Geocode failed with error: %@", error);
return;
}
NSLog(@"Monday");
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(@"placemark.ISOcountryCode %@",placemark.ISOcountryCode);
}];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil)
{
label1.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
lable2.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
答案 0 :(得分:0)
您可以通过地图上的经典用户注释显示用户位置。
如果您想在模拟器中更改位置,只需将gpx文件添加到您的项目中即可。 然后,您将能够通过这种方式在位置之间切换:在xcode&gt; debug&gt;模拟位置
要在地图上添加其他位置,您只需添加注释(MKAnnontations)
答案 1 :(得分:0)
检查以下链接。
http://jprithvi.wordpress.com/tag/display-multiple-pins-in-ios-map/
我希望这就是你要找的东西。
更多链接。
http://jonathanfield.me/mkmapview-adding-pins-map-showing-annotations/
http://mayurbirari.wordpress.com/2011/02/07/how-to-access-mkmapkit-in-iphone/
http://sugartin.info/2011/07/01/map-view-controller-with-multiple-pin-on-google-map/