2016-03-03 3 views
-1

Я пытаюсь получить текущее местоположение в своем UIWebView, но это не сработает. Я попробовал этот код:UIWebView и Google Maps

NSString *website = @"http://www.domain/"; 
NSURL *url = [NSURL URLWithString:website]; 
NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
[webpage loadRequest:request]; 

, что им ищет, чтобы интегрировать текущее местоположение с моей UIWebView Может кто-нибудь сказать мне, как получить текущее местоположение?

+0

ваш вопрос не НКУ ar, не могли бы вы объяснить больше –

+0

@ Anbu.Karthik я просто добавлю его –

+0

как это возможно, бросить, какая цель u пробовала это –

ответ

1

Шаг-1

Добавьте эти два свойства в info.plist

NSLocationAlwaysUsageDescription и ниже собственности

enter image description here

Шаг-2

на ваш взгляд Controlle г вызова метод делегата

#import <CoreLocation/CoreLocation.h> 


@interface ViewController : UIViewController <CLLocationManagerDelegate> 
{ 
CLLocationManager *locationManager; 
} 

@property (strong, nonatomic) NSString *longitude; 
@property (strong, nonatomic) NSString *latitude; 

Шаг-3

on your Implementation File on your `viewDidLoad` 

    - (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    locationManager = [[CLLocationManager alloc] init]; 
    locationManager.delegate = self; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    locationManager.distanceFilter = kCLDistanceFilterNone; 
    if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) 
    { 
     [locationManager requestWhenInUseAuthorization]; 
    } 
    [locationManager startUpdatingLocation]; 

    } 

Шаг-4

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{ 
UIAlertView *errorAlert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"There was an error retrieving your location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
[errorAlert show]; 
NSLog(@"Error: %@",error.description); 
} 

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 
    { 
CLLocation *crnLoc = [locations lastObject]; 
latitude= [NSString stringWithFormat:@"%.8f",crnLoc.coordinate.latitude]; 
longitude = [NSString stringWithFormat:@"%.8f",crnLoc.coordinate.longitude]; 


} 

для образца см this и this

+0

, если вам нужна поддержка, я помогу вам –