【发布时间】:2016-12-21 05:00:13
【问题描述】:
我想根据地址字符串在两个注释引脚之间画一条线。地址标签预先填充了来自用户的数据,可以是美国的任何位置。我已经在每个地址上都有注释,我只是不确定要为坐标数组(纬度、经度)放置什么以便在这两点之间画一条线。我附上了 2 个屏幕截图,以帮助澄清和显示我收到的错误。
以下是我如何注释每个地址:
NSString *location = [(UILabel *)[[self view] viewWithTag:1]text];;
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:location
completionHandler:^(NSArray* placemarks, NSError* error){
if (placemarks && placemarks.count > 0) {
CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
MKCoordinateRegion region = self.mapView.region;
[self.mapView setRegion:region animated:NO];
[self.mapView addAnnotation:placemark];
}
}
];
NSString *location2 = [(UILabel *)[[self view] viewWithTag:6]text];;
CLGeocoder *geocoder2 = [[CLGeocoder alloc] init];
[geocoder2 geocodeAddressString:location2
completionHandler:^(NSArray* placemarks, NSError* error){
if (placemarks && placemarks.count > 0) {
CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
MKCoordinateRegion region = self.mapView.region;
[self.mapView setRegion:region animated:NO];
[self.mapView addAnnotation:placemark];
}
}
];
这是我不知道在坐标数组中放置纬度和经度的错误:
CLLocationCoordinate2D coordinateArray[2];
coordinateArray[0] = CLLocationCoordinate2DMake(lat1, lon1);<- NEED HELP HERE
coordinateArray[2] = CLLocationCoordinate2DMake(lat2, lon2);<- NEED HELP HERE
self.routeLine = [MKPolyline polylineWithCoordinates:coordinateArray count:2];
[self.mapView setVisibleMapRect:[self.routeLine boundingMapRect]]; //If you want the route to be visible
[self.mapView addOverlay:self.routeLine];
【问题讨论】:
标签: ios objective-c google-maps dictionary