xcode – 尝试在Pin上居中地图(MKMapView)

xcode – 尝试在Pin上居中地图(MKMapView),第1张

概述苦苦寻找一种方法来使地图缩放并以注释引脚为中心. Pin下降,但地图加载海洋.代码如下. - (void) connectionDidFinishLoading:(NSURLConnection *)connection{ [self setString]; NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:resp 苦苦寻找一种方法来使地图缩放并以注释引脚为中心. Pin下降,但地图加载海洋.代码如下.
- (voID) connectionDIDFinishLoading:(NSURLConnection *)connection{  [self setString];  NSDictionary *dic = [NSJsONSerialization JsONObjectWithData:responseData options:0 error:nil];  NSDictionary *location = [dic objectForKey:@"location"];  NSDictionary *coordinate = [location objectForKey:@"coordinate"];  Nsstring *lat = [coordinate objectForKey:@"latitude"];  Nsstring *lon = [coordinate objectForKey:@"longitude"];  for (NSDictionary *diction in coordinate)  {    [array addobject:lat];    [array addobject:lon];  }  {    CLLocationCoordinate2D track;    track.latitude = [lat doubleValue];    track.longitude = [lon doubleValue];    MapVIEwAnnotation *newAnnotation = [[MapVIEwAnnotation alloc] initWithTitle:@"Title of Place Here" andCoordinate:track];    [self.mapVIEw addAnnotation:newAnnotation];  }}

第2个问题,非常相关:

在实现上述问题的答案后,我已经修改了我的代码.现在,我的坐标从前一个视图到我的MKMapVIEw,所以我不必费心去做两次API调用,第二个是在MKMapVIEw中.目前在我的VIEwWillAppear中,我有以下内容,并且AGAIN遇到了一个问题,即视图不会居中并放大图钉:

if ([self.stringTodisplay isEqualToString: @"Firehouse gallery"]){    UIImage *img = [UIImage imagenamed:@"firehouse.jpg"];    [imageVIEw setimage:img];    CLLocationCoordinate2D track;    track.latitude = [lat doubleValue];    track.longitude = [lon doubleValue];    MKCoordinateRegion region;    MKCoordinateSpan span;    span.latitudeDelta = 0.01;    span.longitudeDelta = 0.01;    region.span = span;    region.center = track;    MapVIEwAnnotation *newAnnotation = [[MapVIEwAnnotation alloc] initWithTitle:@"Firehouse gallery" andCoordinate:track];    [self.mapVIEw addAnnotation:newAnnotation];    [self.mapVIEw setRegion:region animated:TRUE];    [self.mapVIEw regionThatFits:region];}

反馈非常感谢,因为我不知道还应该做些什么.引脚加载到正确的坐标上,只是没有居中/缩放…

@H_502_13@解决方法@H_502_15@ 试试这个:
{    CLLocationCoordinate2D track;    track.latitude = [lat doubleValue];    track.longitude = [lon doubleValue];    MKCoordinateRegion region;    MKCoordinateSpan span;    span.latitudeDelta = 0.01;    span.longitudeDelta = 0.01;    region.span = span;    region.center = track;    MapVIEwAnnotation *newAnnotation = [[MapVIEwAnnotation alloc] initWithTitle:@"Title of Place Here" andCoordinate:track];    [self.mapVIEw addAnnotation:newAnnotation];    [self.mapVIEw setRegion:region animated:TRUE];    [self.mapVIEw regionThatFits:region];}
总结

以上是内存溢出为你收集整理的xcode – 尝试在Pin上居中地图(MKMapView)全部内容,希望文章能够帮你解决xcode – 尝试在Pin上居中地图(MKMapView)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1098805.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存