gpt4 book ai didi

ios - mkmapview如何通过注解获取位置

转载 作者:行者123 更新时间:2023-11-29 10:22:06 26 4
gpt4 key购买 nike

在我的应用程序中,我使用了 MKmapview 我想在将图钉拖动到图钉时显示位置。

如何通过pin获取位置?我想在将图钉拖动到图钉时显示位置。

-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
self.mapView.centerCoordinate = userLocation.coordinate;
CLLocationDistance distance = 1500;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, distance, distance);
MKCoordinateRegion adjusterRegion = [self.mapView regionThatFits:region];

[self.mapView setRegion:adjusterRegion animated:YES];

self.latitudeValue.text = [NSString stringWithFormat:@"%f",userLocation.coordinate.latitude];
self.longtitudeValue.text = [NSString stringWithFormat:@"%f",userLocation.coordinate.longitude];


custom *location = [[custom alloc] initWithTitle:@"location" subtitle:@"" location:userLocation.coordinate];
[self.mapView addAnnotation:location];

MKCoordinateRegion regions = {{0.0,0.0},{0.0,0.0}};
regions.center.latitude = 13.905726;
regions.center.longitude = 100.52142100000003;
regions.span.latitudeDelta = 0.01f;
regions.span.longitudeDelta = 0.01f;
[self.mapView setRegion:region animated:YES];

customlocation *locs = [[customlocation alloc] initWithTitle:@"test" subtitle:@"" location:regions.center];
[self.mapView addAnnotation:locs];

}


-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{


if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;

static NSString *reuseId = @"pin";
MKPinAnnotationView *pa = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseId];
if (pa == nil)
{
pa = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId];
pa.draggable = YES;
pa.canShowCallout = YES;
}
else
{
pa.annotation = annotation;
}
return pa;
}

请帮助我,我想在将图钉拖动到图钉时显示位置。

最佳答案

请检查这个answer ,这与您正在寻找的答案类似,只是那个人想要在用户放置图钉的地方进行协调。

这里是 same answer对于您提出的问题,

关于ios - mkmapview如何通过注解获取位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34508499/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com