虽然所有标记的坐标相同,但在谷歌地图上看到的地图标记被分散

时间:2017-02-27 07:09:38

标签: ios google-maps location updates marker

我有关于地图标记的问题。我们是三个成员A,B和C.我们一起走在一条路上。我们正在相互更新他们的位置。但是标记没有显示每个成员在一起的位置,标记都是分散的。意思是每个成员的位置不一样。

如果成员A处于正确的坐标,而其他两个成员B和C,则两者都远离成员A而B也远离成员C.

我检查每个成员的坐标。地图GoogleMap本身返回错误的坐标。

有时位置更新会卡住。

配置位置管理器

    self.locationManagerCurrent=[[CLLocationManager alloc]init];
    self.locationManagerCurrent.delegate=self;
    self.locationManagerCurrent.distanceFilter = 1;   //didupdateloaction method will call when user moves 1 meter
    self.locationManagerCurrent.desiredAccuracy=kCLLocationAccuracyBestForNavigation;  //provide precise location but more battery consumer
    self.locationManagerCurrent.activityType = CLActivityTypeOther;   //
    self.locationManagerCurrent.pausesLocationUpdatesAutomatically = YES;

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8) {
        [self.locationManagerCurrent requestAlwaysAuthorization];
    }

    if ([self.locationManagerCurrent respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) {
        [self.locationManagerCurrent setAllowsBackgroundLocationUpdates:YES];
    }
    [self.locationManagerCurrent startMonitoringSignificantLocationChanges];
    [self.locationManagerCurrent startUpdatingLocation];

获取位置坐标

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
    CLLocation *location=[locations objectAtIndex:0];

    if (location.horizontalAccuracy < 0) {
        return;
    }

    // test the age of the location measurement to determine if the measurement is cached
    // in most cases you will not want to rely on cached measurements
    //
    NSTimeInterval locationAge = -[location.timestamp timeIntervalSinceNow];
    if (locationAge > 5.0) {
        return;
    }

      self.currentLatitude=[NSString     stringWithFormat:@"%f",location.coordinate.latitude];
    self.currentLongitude=[NSString stringWithFormat:@"%f",location.coordinate.longitude]; }

以上代码有助于更新各个位置。

更新地图上的所有会员标记

-(void)updateAssigneesMarker
{
    for (GMSMarker *marker in [_arrMarkerAsssignee mutableCopy] ){
        marker.map = nil;
        [_arrMarkerAsssignee removeAllObjects];
    }


    for(int i = 0; i < [_array_assigneesDetails count]; i++)
    {

        assignees_lat=[[[_array_assigneesDetails objectAtIndex:i ] objectForKey:@"latitude"]floatValue];
        assignees_long=[[[_array_assigneesDetails objectAtIndex:i ] objectForKey:@"longitude"]floatValue];
        BOOL assignees_location_status=[[[_array_assigneesDetails objectAtIndex:i] objectForKey:@"user_location_status"] boolValue];

        if (assignees_location_status)
        {
            NSData *iconData = [[NSData alloc] initWithBase64EncodedString:[[_array_assigneesDetails objectAtIndex:i ] objectForKey:@"icon_data"] options:0];
            UIImage *icon_image=[UIImage imageWithData:iconData];

            NSString *name=[NSString stringWithFormat:@"%@ %@",[[_array_assigneesDetails objectAtIndex:i ] objectForKey:@"u_firstname"],[[_array_assigneesDetails objectAtIndex:i ] objectForKey:@"u_lastname"]];

            if(assignees_lat!=00.000000 && assignees_long!=00.000000)
            {
                GMSMarker *marker_assignee = [[GMSMarker alloc] init];
                marker_assignee.position=CLLocationCoordinate2DMake(assignees_lat, assignees_long);
                //marker_assignee.title = name;
                marker_assignee.accessibilityLabel=name;
                marker_assignee.appearAnimation=kGMSMarkerAnimationNone;
                marker_assignee.icon=icon_image;
                if([[[_array_assigneesDetails objectAtIndex:i]objectForKey:@"user_id"] integerValue] == [app.user_id integerValue])
                {
                    marker_assignee.userData = @"Host_Marker";
                }
                [_arrMarkerAsssignee addObject:marker_assignee];
                marker_assignee.map = _view_mapView;
            }
        }
    }
}

我没有得到任何解决方案。 请帮帮我。

谢谢。

0 个答案:

没有答案