2016-07-13 23 views
0

目前我正在开发一款类似于Uber app for iOS设备的应用程序。如何在屏幕中心的Google地图上查看驾驶员当前位置(驾车时)?

出于这个目的,我用谷歌地图SDK

我的查询是: 当他需要看到在地图上永远的中心,他的当前位置与聚线路驱动器的驱动器,距离&总时间走遍

在这里,我找到了一个样本图像与MKMapKit代码:Image URL linkSample code url

我也在寻找相同的代码Google Map具有自定义图像(汽车符号)。

我该如何解决这个问题?请帮助我。

回答

1

如果您是驱动程序,则可以使用Geolocation来检测您的当前位置。

根据此thread,您必须使用CLLocationManager检索位置。

首先,添加CoreLocation.framework到您的项目:

  • 围棋在Project Navigator
  • 选择项目
  • 单击该选项卡上Build Phases
  • 添加CoreLocation.frameworkLink Binary with Libraries

然后,您只需按照Apple documentation的基本示例进行操作即可。

  • 可能在你ViewDidLoad创建CLLocationManager

    if (nil == locationManager) 
        locationManager = [[CLLocationManager alloc] init]; 
    
    locationManager.delegate = self; 
    //Configure Accuracy depending on your needs, default is kCLLocationAccuracyBest 
    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer; 
    
    // Set a movement threshold for new events. 
    locationManager.distanceFilter = 500; // meters 
    
    [locationManager startUpdatingLocation]; 
    

随着每一个位置 更新时间CLLocationManagerDelegate,您可以在Google Maps更新用户的位置:

- (void)locationManager:(CLLocationManager *)manager 
     didUpdateLocations:(NSArray *)locations { 
    // If it's a relatively recent event, turn off updates to save power. 
    CLLocation* location = [locations lastObject]; 
    NSDate* eventDate = location.timestamp; 
    NSTimeInterval howRecent = [eventDate timeIntervalSinceNow]; 
    if (abs(howRecent) < 15.0) { 
     // Update your marker on your map using location.coordinate.latitude 
     //and location.coordinate.longitude); 
    } 
} 

如果您使用本机MapKit.framework,它也可以工作。您需要添加yourMapView.myLocationEnabled = YES;并且框架将完成所有工作。 (除了在你的位置上放置地图)。

按照documentation的步骤操作。如果您想更新地图以跟随您的位置,可以复制框架目录中包含的Google示例MyLocationViewController.m。他们只需在myLocation属性中添加一个观察者即可更新相机属性。

要获得总行程,请检查此related question。它规定您需要将地址编码为纬度/经度,然后您可以使用CLLocation框架计算距离。

要对地址进行地址解析,您可以使用forward geocoding API

// get CLLocation fot both addresses 
CLLocation *location = [[CLLocation alloc] initWithLatitude:address.latitude longitude:address.longitude]; 

// calculate distance between them 
CLLocationDistance distance = [firstLocation distanceFromLocation:secondLocation]; 

您还可以检查此related link

希望这会有所帮助!