使用 ios7 CoreLocation 创建 Google Maps 链接

Posted

技术标签:

【中文标题】使用 ios7 CoreLocation 创建 Google Maps 链接【英文标题】:Use ios7 CoreLocation to create Google Maps link 【发布时间】:2014-03-16 19:48:28 【问题描述】:

ios 开发新手,需要一点帮助。 我正在尝试使用 CoreLocation 将用户当前位置加载到格式化为 Google 地图链接 (http://maps.google.com/maps?q=loc:userLatitude,-userLongitude) 的 UITextField,以便我可以在短信中分享。任何人都可以建议或指向我可以查看的示例。

请,谢谢。

我猜我不够清楚。我想使用 corelocation 将当前的纬度和经度传递给这个字符串 (http:/maps.google.com/maps?q=loc:currentLat,-currentLong) 并加载它到一个 UITextField。 即:如果你在多伦多, uitextField 会有这个链接

http://maps.google.com/maps?q=loc:43.653433,-79.380341

对于任何感兴趣的人,我自己解决了。

【问题讨论】:

What parameters should I use in a Google Maps URL to go to a lat-lon?的可能重复 这不是重复的 【参考方案1】:
     #import "ViewController.h"

          @interface ViewController ()

        @property (strong, nonatomic) CLLocationManager *manager;

     @property (strong, nonatomic) IBOutlet UITextField *MyLocation;
    @property (strong, nonatomic) IBOutlet UILabel *addressLabel;

     @end

    @implementation ViewController

     - (void)viewDidLoad
          
         [super viewDidLoad];
  [self startLocations];
              

          - (void)didReceiveMemoryWarning
          
            [super didReceiveMemoryWarning];
         // Dispose of any resources that can be recreated.
         

          #pragma mark - Location Manager

         - (CLLocationManager *)manager 

        if (!_manager) 
    _manager = [[CLLocationManager alloc]init];
    _manager.delegate = self;
    _manager.desiredAccuracy = kCLLocationAccuracyBest;
        
         return _manager;
          

           - (void)startLocations 

          // create and start the location manager

         [self.manager startUpdatingLocation];
      
        - (void)stopLocations 

           // create and start the location manager

           [self.manager stopUpdatingLocation];
         
          - (void)locationManager:(CLLocationManager *)manager
        didFailWithError:(NSError *)error
     
         NSLog(@"Error: %@", [error description]);
      
    - (void)locationManager:(CLLocationManager *)manager 
             didUpdateLocations:(NSArray *)locations 



     // grab current location and display it in a label
       CLLocation *currentLocation = [locations lastObject];

   NSString *here = [
  NSString stringWithFormat:@"http://maps.google.com/maps?q=loc:
       %f,%f",currentLocation.coordinate.
         latitude,currentLocation.
   coordinate.longitude];
   self.MyLocation.text = here;

// and update our Map View
[self updateMapView:currentLocation];




  #pragma mark - Map Kit

  - (void)updateMapView:(CLLocation *)location 


// create an address from our coordinates
CLGeocoder *geocoder = [[CLGeocoder alloc]init];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks,
 NSError *error) 
   
    CLPlacemark *placemark = [placemarks lastObject];
    NSString *address = [NSString stringWithFormat:@"%@, %@, %@, 
   %@, %@, %@",    placemark.subThoroughfare,placemark.
 thoroughfare, placemark.locality, placemark.administrativeArea,
 placemark.postalCode,placemark.
   ISOcountryCode];
    if (placemark.thoroughfare != NULL) 
        self.addressLabel.text = address;
     else 
        self.addressLabel.text = @"";
    
   ];
  [self stopLocations];

    @end

【讨论】:

以上是关于使用 ios7 CoreLocation 创建 Google Maps 链接的主要内容,如果未能解决你的问题,请参考以下文章

CoreLocation - iOS 7 中的区域监控问题

CoreLocation框架之APP定位

地理围栏不再从 ios7 中的终止状态重新启动应用程序?

手机重启后 iBeacon 监控/测距

在 OS X 上使用 python 的 CoreLocation

地图和定位功能的实现-篇幅略大,手机慎入