У меня есть данные о широте и долготе местоположения, как я могу сделать это ссылкой на Карты Google, когда пользователь нажимает на ссылку и выбирает вариант, например, электронную почту.
Вот код, который я использую для получения данных о местоположении:
// Вот файл .h
@interface locate : UIViewController <CLLocationManagerDelegate,MKMapViewDelegate>
{
CGPoint gestureStartPoint;
CLLocationManager *locationManager;
CLLocation *startingPoint;
UILabel *latitudeLabel;
UILabel *longitudeLabel;
UILabel *altitudeLabel;
MKMapView *mapView;
}
@property (assign) CGPoint gestureStartPoint;
@property (nonatomic, retain) CLLocationManager *locationManager;
@property (nonatomic, retain) CLLocation *startingPoint;
@property (nonatomic, retain) IBOutlet UILabel *latitudeLabel;
@property (nonatomic, retain) IBOutlet UILabel *longitudeLabel;
@property (nonatomic, retain) IBOutlet UILabel *altitudeLabel;
@property (nonatomic, retain) IBOutlet MKMapView *mapView;
@end
// Вот файл .m
#import "locate.h"
@implementation locate
@synthesize gestureStartPoint,locationManager,startingPoint,latitudeLabel,longitudeLabel,altitudeLabel,mapView;
- (void)dealloc
{
[locationManager release];
[startingPoint release];
[latitudeLabel release];
[longitudeLabel release];
[altitudeLabel release];
[super dealloc];
}
- (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
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
if (startingPoint == nil)
self.startingPoint = newLocation;
NSString *latitudeString = [[NSString alloc] initWithFormat:@"%g\u00B0",
newLocation.coordinate.latitude];
latitudeLabel.text = latitudeString;
[latitudeString release];
NSString *longitudeString = [[NSString alloc] initWithFormat:@"%g\u00B0",
newLocation.coordinate.longitude];
longitudeLabel.text = longitudeString;
[longitudeString release];
NSString *altitudeString = [[NSString alloc] initWithFormat:@"%gm",
newLocation.altitude];
altitudeLabel.text = altitudeString;
[altitudeString release];
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error {
NSString *errorType = (error.code == kCLErrorDenied) ?
@"Access Denied" : @"Unknown Error";
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Error getting Location"
message:errorType
delegate:nil
cancelButtonTitle:@"Okay"
otherButtonTitles:nil];
[alert show];
[alert release];
}
- (void)viewDidLoad
{
self.locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
mapView.delegate = self;
mapView.mapType = MKMapTypeStandard;
[super viewDidLoad];
}
- (void)viewDidUnload
{
self.locationManager = nil;
self.latitudeLabel = nil;
self.longitudeLabel = nil;
self.altitudeLabel = nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
@end
Теперь, пожалуйста, кто-нибудь, помогите мне, как я могу использовать данные о местоположении для создания ссылки на Google Карты?