在Google Map iOS上使用来自Firebase - GeoFire的位置数据移动地图标记?

时间:2017-03-15 08:42:32

标签: ios objective-c firebase google-maps-sdk-ios geofire

我正在开发使用Google Map SDK,Firebase和Geofire的iOS Taxi应用程序。我需要显示出租车司机在乘客位置周围的实时移动,当他/她在地图上更改他的取件位置时(这发生在乘客要求租用之前,只是检查用户位置周围的司机附近)。

我已成功将geofire集成到应用程序中,但我想知道如何在地图上平滑移动标记。是否只能删除地图上的所有标记并逐个添加它们,我认为这是一个糟糕的实现。还有更好的选择吗?

//The location of a key now matches the query criteria.
GFQuery *query = [geoFire queryAtLocation:L(coor.latitude, coor.longitude) withRadius:1];
[query observeEventType:GFEventTypeKeyEntered withBlock:^(NSString *key, CLLocation *location) {
    NSLog(@"Entered Key '%@' entered the search area and is at location '%@'", key, location);
    //Remove all markers and add location received from this block?
}];

//The location of a key no longer matches the query criteria.
[query observeEventType:GFEventTypeKeyExited withBlock:^(NSString *key, CLLocation *location) {
    NSLog(@"Exited Key '%@' entered the search area and is at location '%@'", key, location);
    //Remove all markers and add location received from this block?
}];

//The location of a key changed but the location still matches the query criteria.
[query observeEventType:GFEventTypeKeyMoved withBlock:^(NSString *key, CLLocation *location) {
    NSLog(@"Moved Key '%@' entered the search area and is at location '%@'", key, location);
    //Remove all markers and add location received from this block?
}];

如果有人这样做,请先提供一些示例代码段,以更好的方式实现这一点。

1 个答案:

答案 0 :(得分:0)

删除地图上的所有标记并再次添加它们将是严重不好的解决方案。您可以使用GMSMarker的位置属性来移动您的标记,并使用CATransaction来提供移动效果。

Eg. Mall moveMarkerPositionWithMotion method to change location of your marker

-(void)moveMarkerPositionWithMotion {
    [CATransaction begin];
    NSTimeInterval nAnimationDuration = 1; // Update this value as per your needs.
    [CATransaction setAnimationDuration:nAnimationDuration];
    marker.position = coordindates;
    [CATransaction commit];
}