“小地图”在 UITableView 中

发布于 2024-11-07 13:08:07 字数 162 浏览 1 评论 0原文

如何在我的 UITableViewController 中添加“迷你地图”?

我想使用与地图应用程序相同的“设计/布局”。请参阅:

在此处输入图像描述

How can I add a "mini-map" in my UITableViewController?

I would like to use the same "design/layout" as with Maps app. Please see:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

趁微风不噪 2024-11-14 13:08:07

您可能会考虑使用 Google Static,而不是在 UI 中使用功能齐全的 MKMapView地图 API。您只需使用适当的位置格式化 URL 并异步返回图像即可。您可以将结果粘贴在 UIImageView< /a>:

http://maps.google.com/maps/api/staticmap?center=kakn%C3%A4stornet&size=88x88&maptype=roadmap&sensor=false

http://maps.google.com/maps/api/staticmap?center=kakn%C3%A4stornet& size=88x88&maptype=roadmap&sensor=false

只需确保缓存结果,这样就不会每次有人运行您的应用程序时都访问 Google 服务器。

以下是包含标记的网址:

http://maps.google.com/maps/api/staticmap?center=kakn%C3%A4stornet&size=88x88&maptype=roadmap&markers=size:tiny|color:green|kakn%C3%A4stornet&sensor=false

在此处输入图像描述

You might consider, rather than having a fully functional MKMapView in your UI, use the Google Static Maps API. You can just format a URL with the appropriate location and get back an image asynchronously. You can stick the results in a UIImageView:

http://maps.google.com/maps/api/staticmap?center=kakn%C3%A4stornet&size=88x88&maptype=roadmap&sensor=false

http://maps.google.com/maps/api/staticmap?center=kakn%C3%A4stornet&size=88x88&maptype=roadmap&sensor=false

Just make sure you cache the results, so you aren't hitting Google servers every time someone runs your app.

Here is a URL with a marker included:

http://maps.google.com/maps/api/staticmap?center=kakn%C3%A4stornet&size=88x88&maptype=roadmap&markers=size:tiny|color:green|kakn%C3%A4stornet&sensor=false

enter image description here

宛菡 2024-11-14 13:08:07

我想通了,或者至少差不多了。感谢@AhmadTK。

这是我的代码:

#import <MapKit/MapKit.h>
#import "RackAnnotation.h"

#import <QuartzCore/CATransaction.h>
#import <QuartzCore/CAAnimation.h>

[...]

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }

        [cell.textLabel setText:theAnnotationSet._address];

        [cell.textLabel setShadowColor:[UIColor whiteColor]];
        [cell.textLabel setShadowOffset:CGSizeMake(0, 1)];

        MKMapView *mapView=[[MKMapView alloc] initWithFrame:CGRectMake(1, 1, 68, 68)];
        mapView.mapType=MKMapTypeStandard;
        mapView.showsUserLocation=NO;
        [mapView setContentMode:UIViewContentModeBottomRight];

        MKCoordinateRegion region;
        region.center=theAnnotationSet._coordinate;

        MKCoordinateSpan span;
        span.latitudeDelta = 0.01;
        span.longitudeDelta = 0.01;
        region.span=span;

        [mapView setRegion:region animated:NO];
        [mapView addAnnotation:theAnnotationSet];
        [mapView setScrollEnabled:NO];
        [mapView setUserInteractionEnabled:NO];

        UIButton *mapButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 70)];
        [mapButton setBackgroundColor:[UIColor grayColor]];

        CALayer *mapLayer = mapView.layer;
        mapLayer.masksToBounds = YES;
        mapLayer.cornerRadius = 10.0;

        [mapButton addSubview:mapView];
        [mapButton setContentEdgeInsets:UIEdgeInsetsMake(1, 1, 1, 1)];

        CALayer *layer = mapButton.layer;
        layer.masksToBounds = YES;
        layer.cornerRadius = 10.0;

        [cell addSubview:mapButton];
        [cell setAccessoryView:mapButton];
        [cell setEditing:YES];

        NSLog(@"Title: %@", theAnnotationSet._address);

        return cell;

    }
    else {
        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }


        return cell;
    }
}

这是结果:

在此处输入图像描述

我剩下的唯一问题是将其放在左侧。据我所知,这只能通过使用您自己的子类和 UITableViewCell 或将您自己的视图设置为标题来完成。

我剩下要弄清楚的另一件事是如何删除这个小地图中的“Googl”。我的意思是,我在主地图上有它,但现在它只是让我烦恼。

干杯,
保罗·皮伦

I figured it out, or at least almost. Thanks to @AhmadTK.

This is my code:

#import <MapKit/MapKit.h>
#import "RackAnnotation.h"

#import <QuartzCore/CATransaction.h>
#import <QuartzCore/CAAnimation.h>

[...]

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }

        [cell.textLabel setText:theAnnotationSet._address];

        [cell.textLabel setShadowColor:[UIColor whiteColor]];
        [cell.textLabel setShadowOffset:CGSizeMake(0, 1)];

        MKMapView *mapView=[[MKMapView alloc] initWithFrame:CGRectMake(1, 1, 68, 68)];
        mapView.mapType=MKMapTypeStandard;
        mapView.showsUserLocation=NO;
        [mapView setContentMode:UIViewContentModeBottomRight];

        MKCoordinateRegion region;
        region.center=theAnnotationSet._coordinate;

        MKCoordinateSpan span;
        span.latitudeDelta = 0.01;
        span.longitudeDelta = 0.01;
        region.span=span;

        [mapView setRegion:region animated:NO];
        [mapView addAnnotation:theAnnotationSet];
        [mapView setScrollEnabled:NO];
        [mapView setUserInteractionEnabled:NO];

        UIButton *mapButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 70)];
        [mapButton setBackgroundColor:[UIColor grayColor]];

        CALayer *mapLayer = mapView.layer;
        mapLayer.masksToBounds = YES;
        mapLayer.cornerRadius = 10.0;

        [mapButton addSubview:mapView];
        [mapButton setContentEdgeInsets:UIEdgeInsetsMake(1, 1, 1, 1)];

        CALayer *layer = mapButton.layer;
        layer.masksToBounds = YES;
        layer.cornerRadius = 10.0;

        [cell addSubview:mapButton];
        [cell setAccessoryView:mapButton];
        [cell setEditing:YES];

        NSLog(@"Title: %@", theAnnotationSet._address);

        return cell;

    }
    else {
        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }


        return cell;
    }
}

And this is the result:

enter image description here

The only problem I have left is getting it on the left side. As far as I can see that can only be done by using your own subclass and either UITableViewCell or set your own view as header.

The other thing I have left to figure out is how to remove "Googl" in this mini-map. I mean, I have it in the main map and now its just annoying me.

Cheers,
Paul Peelen

生来就爱笑 2024-11-14 13:08:07

我相信您在问题中的示例是通过 UITableView header view 实现的。尝试将 UIView 拖到您的 UITableView Controller 上,并自定义该 UIView。它应该比修改 TableViewCell 容易得多。

参考:

UITableView 标题(不是节标题)问题

I believe your example in the question is achieved with UITableView header view. Try dragging a UIView to you UITableView Controller, and customize that UIView. It should be much easier than modifying a TableViewCell.

Reference:

UITableView Header (not section header) problem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文