2016-03-03 92 views
-1

我试图在我的UIWebView中获取当前位置,但它不起作用。我想这样的代码:UIWebView和谷歌地图

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

什么即时寻找是当前位置与我的UIWebView 整合谁能告诉我如何获得当前位置?

+0

你的问题不是CLE AR,你能解释一下吗 –

+0

@ Anbu.Karthik我只是加了它 –

+0

怎么可能兄弟,你试过这个的目的是什么 –

回答

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]; 


} 

样品看到thisthis

+0

如果你需要支持,我会帮你 –