显示当前位置以及 iPhone 中的另一个位置
每当我们加载地图视图时,它都会自动正确显示当前用户位置。就我而言,我在地图上显示另一个位置,以便地图加载当前位置并缩放到我给出的位置..但是,当前位置点没有显示(自动出现的蓝色点..)。 我已经给出了mapView.showCurrentLocation=TRUE;但它没有显示。 所以任何人都可以告诉它的工作方式,它应该说出当前位置标记,然后缩放到我给出的点。 谢谢
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString *defaultPinID = @"CameraAnnotation";
MKPinAnnotationView *retval = nil;
static int postag=1;
(MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if(annotation=MapView.userLocation)
{
return nil;
}
// If we have to, create a new view
else if (retval == nil)
{
retval = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
myDetailButton.frame = CGRectMake(0, 0, 50, 23);
myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
myDetailButton.tag=postag;
postag++;
[myDetailButton addTarget:self action:@selector(showLinks:) forControlEvents:UIControlEventTouchUpInside];
retval.rightCalloutAccessoryView = myDetailButton;
[retval setPinColor:MKPinAnnotationColorRed];
retval.animatesDrop = YES;
retval.canShowCallout = YES;
}
return retval;
}
whenever we load a mapview ,it automaticallay shows the current user location right. In my case i am showing another location on map ,such that the map loads the current location and zoomed to the location i have given .. but, the current location point was not showing (the blue one which comes automaticay..).
i have given mapView.showCurrentLocation=TRUE; but its not showing .
so could any one tells the way it works and it should say the current location mark and then zoomed to the point i have given.
Thanks
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString *defaultPinID = @"CameraAnnotation";
MKPinAnnotationView *retval = nil;
static int postag=1;
(MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if(annotation=MapView.userLocation)
{
return nil;
}
// If we have to, create a new view
else if (retval == nil)
{
retval = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
myDetailButton.frame = CGRectMake(0, 0, 50, 23);
myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
myDetailButton.tag=postag;
postag++;
[myDetailButton addTarget:self action:@selector(showLinks:) forControlEvents:UIControlEventTouchUpInside];
retval.rightCalloutAccessoryView = myDetailButton;
[retval setPinColor:MKPinAnnotationColorRed];
retval.animatesDrop = YES;
retval.canShowCallout = YES;
}
return retval;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在模拟器中,默认的当前位置是库比蒂诺。这就是您所看到的,它将在设备中正常工作。
此外,您应该使用 CLLocationManager 来获取当前位置。
更改图钉颜色 祝
一切顺利。
In simulator the default current location is Cupertino.This is what you are seeing, it will work properly in device.
More over you should use CLLocationManager to get the current location.
To change the pin color
All the best.
看看答案 在这个问题上设置 MkMapView 缩放级别以包含附加到它的所有 MKAnnotations
take a look at the answer on this question to set the MkMapView zoom level to encompass all the MKAnnotations attached to it