我已经看过关于如何进行反向地理编码的演示之后的API文档和演示 - 获取一个地址,给定一个Lat/Long位置.我需要做相反的事情.我假设这已经解决了问题,因为Apple的MapKit API完全避免了它.
有没有办法在模拟器中使用真实位置服务(不涉及设备)?它总是去库比蒂诺.
我是MapKit for iPhone的新手,试图实现这个,由于某种原因我看不到当前位置的蓝点,其他人都有这个问题????
#import "DetailMapViewController.h"
#import "mapAnnotations.h"
@implementation DetailMapViewController
@synthesize inStock;
-(void)getlocation:(CLLocationCoordinate2D)loc
{
location = loc;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = @"Street View";
mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
mapView.delegate=self;
//MKCoordinateRegion region;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, 5000, 5000);
mapAnnotations *ann = [[mapAnnotations alloc] init];
ann.title = @"";
ann.subtitle = @"";
ann.coordinate = region.center;
mapView.showsUserLocation = YES;
[mapView addAnnotation:ann];
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
[self.view insertSubview:mapView atIndex:0];
}
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
MKPinAnnotationView *annView=[[MKPinAnnotationView …Run Code Online (Sandbox Code Playgroud) 背景:我正在构建一系列基于位置的应用程序,这些应用程序大量使用地图.这些地图使用从服务器获取的位置进行注释,我向其传递了我需要数据的地图区域(定义为lat/long和latDelta/longDelta,非常类似于MKCoordinateRegion,但具有不同的参考坐标位置) .我正在编写一堆帮助方法/类来管理这些区域.需要与iOS 3.x的兼容性(意味着MKMapRect已经出局).
问题:我是否通过将MKCoordinateRegions视为矩形来为自己做好准备?具体来说,我将它们的几何形状视为矩形的几何形状,假设它们具有与矩形基本相同的属性.我已经实现了几个镜像CGRect的辅助方法的方法,比如MKCoordinateRegionUnion/Inset/Outset等,它们都通过了我的单元测试,但我开始质疑我的基本假设是否正确.我知道事实上MKCoordinateRegion并不代表一个几何矩形,而是一个由两组平行平面约束的球面区域,彼此垂直(如果有人可以为我提供一个更好的术语,可以获得奖励积分).
我还没有遇到任何异常现象,但由于很多应用程序都依赖于我对几何的理解,所以我现在想弄清楚我是否走错了路.我在学校里处理大多数处理三维径向几何学的课程这一事实并没有让我对我的直觉是正确的充满信心.
假设我有一个由4个CLLocationCoordinate2D点组成的正方形,它们位于lat,lon,我想找到以米为单位的正方形区域.我将CLLocationCoordinate2D点转换为MKMapPoints,并在XY空间中找到该区域.但是,我找到的区域是MKMapPoint的单位,它不直接转换为米.如何将MKMapPoint-space中的这个区域翻译成米?
我也陷入了困境,我正试图把一个NSString或一个NSNumber放进initWithLatitude去CLLocation.如果有人能提供帮助就会很棒.
继承人的代码
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:53.778702 longitude:-0.271887];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:53.683267 longitude:-0.011330];
label.text = [NSString stringWithFormat:@"Distance in miles: %4.1f", [location1 distanceFromLocation:location2]/1609.344];
[location1 release];
Run Code Online (Sandbox Code Playgroud)
我试图取代[[CLLocation alloc] initWithLatitude:53.778702 longitude:-0.271887]与[[CLLocation alloc] initWithLatitude:lat longitude:lon]
认为使用我自己的自定义图钉进行注释会非常容易.
但我从来没有能够让它工作,我不明白为什么!
我只是使用:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if([annotation isKindOfClass:[MKUserLocation class]])
return nil;
NSString *annotationIdentifier = @"CustomViewAnnotation";
CustomAnnotationView * customAnnotationView = (CustomAnnotationView *) [self.mapview dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if(!customAnnotationView)
{
customAnnotationView=[[CustomAnnotationView alloc] initWithAnnotationWithImage:annotation
reuseIdentifier:annotationIdentifier
annotationViewImage:[UIImage imageNamed:@"map_location_pin.png"]];
}
customAnnotationView.image=[UIImage imageNamed:@"map_location_pin.png"];
customAnnotationView.canShowCallout= YES;
return customAnnotationView;
}
Run Code Online (Sandbox Code Playgroud)
我认为这应该有效,因为UIImage是它想要的东西,而且我的项目中确实有.png文件.
它从不使用我的图像,只是标准的红色图钉.我在这做错了什么?
我调用了我的MKAnnotationView委托方法,因为我可以看到我的NSLog输出.但是这些引脚没有出现在地图上.这里有什么我想念的吗?
MapViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface MapViewController : UIViewController <MKMapViewDelegate>
@property (weak, nonatomic) IBOutlet MKMapView *nearbyMapView;
@end
Run Code Online (Sandbox Code Playgroud)
MapViewController.m
#import "MapViewController.h"
#import "AppDelegate.h"
@interface MapViewController ()
@end
@implementation MapViewController
AppDelegate *appDelegate;
- (void)viewDidLoad
{
[super viewDidLoad];
appDelegate=[[UIApplication sharedApplication] delegate];
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(54.995184, -1.566699);
MKCoordinateSpan span = MKCoordinateSpanMake(0.5, 0.5);
MKCoordinateRegion regionToDisplay = MKCoordinateRegionMake(center, span);
[self.nearbyMapView setRegion: regionToDisplay];
for (int i = 0; i < [[appDelegate offersFeeds] count]; i++) {
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
NSString *plotAddress = [[[appDelegate offersFeeds] …Run Code Online (Sandbox Code Playgroud) 我想drawMapRect:zoomScale:inContext:根据Google Maps使用的映射平台的标准[0-20]缩放级别编写一些绘图规则,但我似乎无法找到将MKZoomScale转换为该范围的公式.任何接受者?
我正在尝试更改iOS的集群注释mapkit的默认颜色,swift.
可能吗.我可以更改单个注释,但不能更改群集.
以下是我的代码.
@available(iOS 11.0, *)
func mapView(_ mapView: MKMapView, clusterAnnotationForMemberAnnotations memberAnnotations: [MKAnnotation]) -> MKClusterAnnotation {
let vehicles = MKClusterAnnotation(memberAnnotations: memberAnnotations)
vehicles.title = "Photos"
vehicles.subtitle = nil
return vehicles
}
Run Code Online (Sandbox Code Playgroud) mapkit ×10
ios ×6
iphone ×5
objective-c ×2
annotations ×1
cllocation ×1
cocoa-touch ×1
geocoding ×1
geolocation ×1
geometry ×1
google-maps ×1
mkmapview ×1
swift ×1