MKPolyLine 在 MAP 上不可见
我有以下代码...
DistanceInformation *distanceInformation=[[DistanceInformation alloc]init];
NSArray *latLongArray=[distanceInformation calculateDistance];
[distanceInformation release];
NSLog(@"lat l %@",latLongArray);
NSUInteger length,count;
length = [[latLongArray objectAtIndex:0] count];
//Calcualte center of the map based on current location and airport location
CLLocationCoordinate2D centerOfMap;
centerOfMap.latitude = (27.1766700 + 28.6361600)/2;
centerOfMap.longitude = (78.0080700 + 78.0526500)/2;
//Set map span according to the distance between airport and user location
CGFloat zoomingLevel;
//set the zoom level of the map according to the distance to airport
if([[latLongArray objectAtIndex:2] intValue] <= 50)
zoomingLevel = 0.2;
else if(([[latLongArray objectAtIndex:2] intValue] > 50)&&([[latLongArray objectAtIndex:2] intValue] <= 100))
zoomingLevel = 0.6;
else if(([[latLongArray objectAtIndex:2] intValue]> 100)&&([[latLongArray objectAtIndex:2] intValue] <= 500))
zoomingLevel = 1.7;
else if(([[latLongArray objectAtIndex:2] intValue] > 500)&&([[latLongArray objectAtIndex:2] intValue] <= 1000))
zoomingLevel = 2.0;
else
zoomingLevel = 2.5;
NSLog(@"Center of map: %f, %f",centerOfMap.latitude, centerOfMap.longitude);
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=zoomingLevel;
span.longitudeDelta=zoomingLevel;
region.span = span;
region.center = centerOfMap;
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
CLLocationCoordinate2D coords[length];
for (count = 0; count<length; count++) {
NSLog(@"coo ");
coords[count] = CLLocationCoordinate2DMake([[[latLongArray objectAtIndex:0] objectAtIndex:count] doubleValue], [[[latLongArray objectAtIndex:1] objectAtIndex:count] doubleValue]);
}
//Display polyline containing route points as an overlay over the mapview
MKPolyline *polyLine=[MKPolyline polylineWithCoordinates:coords count:length];
NSLog(@"polyLine.pointCount %d",polyLine.pointCount) ;
[mapView addOverlay:polyLine];
[polyLine release];
但折线在地图上不可见。折线正在使用我检查过的值进行初始化。
i have the following code...
DistanceInformation *distanceInformation=[[DistanceInformation alloc]init];
NSArray *latLongArray=[distanceInformation calculateDistance];
[distanceInformation release];
NSLog(@"lat l %@",latLongArray);
NSUInteger length,count;
length = [[latLongArray objectAtIndex:0] count];
//Calcualte center of the map based on current location and airport location
CLLocationCoordinate2D centerOfMap;
centerOfMap.latitude = (27.1766700 + 28.6361600)/2;
centerOfMap.longitude = (78.0080700 + 78.0526500)/2;
//Set map span according to the distance between airport and user location
CGFloat zoomingLevel;
//set the zoom level of the map according to the distance to airport
if([[latLongArray objectAtIndex:2] intValue] <= 50)
zoomingLevel = 0.2;
else if(([[latLongArray objectAtIndex:2] intValue] > 50)&&([[latLongArray objectAtIndex:2] intValue] <= 100))
zoomingLevel = 0.6;
else if(([[latLongArray objectAtIndex:2] intValue]> 100)&&([[latLongArray objectAtIndex:2] intValue] <= 500))
zoomingLevel = 1.7;
else if(([[latLongArray objectAtIndex:2] intValue] > 500)&&([[latLongArray objectAtIndex:2] intValue] <= 1000))
zoomingLevel = 2.0;
else
zoomingLevel = 2.5;
NSLog(@"Center of map: %f, %f",centerOfMap.latitude, centerOfMap.longitude);
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=zoomingLevel;
span.longitudeDelta=zoomingLevel;
region.span = span;
region.center = centerOfMap;
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
CLLocationCoordinate2D coords[length];
for (count = 0; count<length; count++) {
NSLog(@"coo ");
coords[count] = CLLocationCoordinate2DMake([[[latLongArray objectAtIndex:0] objectAtIndex:count] doubleValue], [[[latLongArray objectAtIndex:1] objectAtIndex:count] doubleValue]);
}
//Display polyline containing route points as an overlay over the mapview
MKPolyline *polyLine=[MKPolyline polylineWithCoordinates:coords count:length];
NSLog(@"polyLine.pointCount %d",polyLine.pointCount) ;
[mapView addOverlay:polyLine];
[polyLine release];
but the polyline is not visible on map. The polyline is getting initialized with values that I have checked..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我这边的菜鸟错误...忘记实现 MKMapViewDelegate 方法..
Noob mistake on my side... Forgot to implement the MKMapViewDelegate method..