【问题标题】:In IOS track user location in Google Map在 IOS 中跟踪 Google Map 中的用户位置
【发布时间】:2015-07-07 07:10:49
【问题描述】:

我在我的 iOS 项目中使用谷歌地图 SDK 来跟踪用户位置并为他的移动绘制用户路径的路线线。我想为用户的起点添加两个图像,为用户移动添加另一个图像.我无法添加这些图像。请帮我添加这些图像。这是我的代码:

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{

//get the latest location
CLLocation *currentLocation = [locations lastObject];

//store latest location in stored track array;
[self.locations addObject:currentLocation];

//get latest location coordinates
CLLocationDegrees Latitude = currentLocation.coordinate.latitude;
CLLocationDegrees Longitude = currentLocation.coordinate.longitude;
CLLocationCoordinate2D locationCoordinates = CLLocationCoordinate2DMake(Latitude, Longitude);

//zoom map to show users location
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(locationCoordinates, 1000,1000);

MKCoordinateRegion adjustedRegion = [mapview regionThatFits:viewRegion];
[mapview setRegion:adjustedRegion animated:YES];


NSInteger numberOfSteps = self.locations.count;

CLLocationCoordinate2D coordinates[numberOfSteps];
for (NSInteger index = 0; index < numberOfSteps; index++) {
    CLLocation *location = [self.locations objectAtIndex:index];
    CLLocationCoordinate2D coordinate2 = location.coordinate;

    coordinates[index] = coordinate2;
}

MKPolyline *polyLine = [MKPolyline polylineWithCoordinates:coordinates count:numberOfSteps];
[mapview addOverlay:polyLine];

}

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    MKPolylineView *polylineView = [[MKPolylineView alloc]     initWithPolyline:overlay];
    polylineView.strokeColor = [UIColor redColor];
    polylineView.lineWidth = 10.0;
    return polylineView;
}

此代码绘制用户路径。但我想要这种类型的output。 有人请帮助我。

【问题讨论】:

    标签: ios xcode


    【解决方案1】:

    为地图视图添加注释,用于 self.locations 数组的第一个和最后一个对象。每次将位置更新为新位置时,您还需要删除旧注释。

    【讨论】:

      【解决方案2】:

      设 centerY 和 centerX 为图像的中心点

      CLLocationDegrees offset = 0.01;  // change size here
        CLLocationDegrees southWestY = centerY - offset;
        CLLocationDegrees southWestX = centerX - offset;
        CLLocationDegrees northEastY = centerY + offset;
        CLLocationDegrees northEastX = centerX + offset;
      
        CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(southWestY,southWestX);
        CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(northEastY,northEastX);
        GMSCoordinateBounds *overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:southWest coordinate:northEast];
      
        GMSGroundOverlay *overlay = [GMSGroundOverlay groundOverlayWithBounds:overlayBounds icon:[UIImage imagedNamed:@"YourImage.png"]];
        overlay.bearing = 0;
        overlay.map = self.mapView
      

      使用这种方法(与标记不同),图像将随着用户放大/缩小地图而放大和缩小。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-04
        • 2013-02-09
        • 1970-01-01
        • 2016-11-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多