任何有关以下问题的建议都将受到赞赏.
我正在使用以下代码将自定义图像添加到注释中.
- (MKAnnotationView *)mapView:(MKMapView *)mapView
viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isMemberOfClass:[MKUserLocation class]])
{
return nil;
}
if ([annotation isMemberOfClass:[SpectatorPin class]])
{
SpectatorPin *sp = (SpectatorPin *)annotation;
MKAnnotationView *view = [self.mapView dequeueReusableAnnotationViewWithIdentifier:@"specPin"];
if (view == nil) {
view = [[[MKPinAnnotationView alloc] initWithAnnotation:sp reuseIdentifier:@"specPin"] autorelease];
}
view.image = [UIImage imageNamed:@"mylocation20x20.png"];
view.canShowCallout = YES;
view.annotation=annotation;
return view;
}
//Should not get here
return nil;
}
Run Code Online (Sandbox Code Playgroud)
最初正确显示图像.
我有一个段控件,可以更改地图类型(标准,卫星,混合).标准是默认值.一旦我选择卫星,图像立即变为一个引脚.不再调用mapView:viewforAnnotation方法.
问候,
吉姆
我想MKLocalSearch用于在地图中搜索.此功能在iOS 6.1+中可用.有谁知道如何使用这个或任何人都可以举例说明如何使用MKLocalSearch?
想知道什么是从任何位置到我当前位置获得ETA(估计到达时间)的正确方法,考虑到以下情况:
一个.恩. - 我从其他设备得到了它的位置(经度/纬度),并希望当对方会接我......在这种情况下,我可以使用什么网络服务来获取用户这个信息?mapkit是否提供了这种选择?
湾 在情况下,将在服务器端进行,我会只是给我的用户的位置,什么是我的服务器端程序员可以用它来获得ETA信息,以便把它送回来给我的用户的工具?
谢谢大家.
我看到了这个问题:有没有办法使用Apple的Maps API确定两个地点之间的驾驶时间? - 问题,正如我在其他地方发现的那样(据我的理解)是谷歌api需要使用现在没有安装在每个iOS用户上的谷歌地图应用程序.
我正在使用iOS 7 MapKit API在地图上生成3D相机移动,该地图显示MKDirectionsRequest生成的路径.该路径由MKOverlayRenderer呈现,如下所示:
-(void)showRoute:(MKDirectionsResponse *)response
{
for (MKRoute *route in response.routes)
{
[self.map
addOverlay:route.polyline level:MKOverlayLevelAboveRoads];
}
}
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id < MKOverlay >)overlay
{
MKPolylineRenderer *renderer =
[[MKPolylineRenderer alloc] initWithOverlay:overlay];
UIColor *mapOverlayColor = [UIColor colorWithRed:((float)22 / 255.0f) green:((float)126 / 255.0f) blue:((float)251 / 255.0f) alpha:0.8];
renderer.strokeColor = mapOverlayColor;
renderer.lineWidth = 13.0;
return renderer;
}
Run Code Online (Sandbox Code Playgroud)
除了一个问题,它运作良好.当我使用MKMapCameras缩放或平移路径时(如果我只是以用户身份执行此操作),则路径呈锯齿状,如此屏幕截图所示:

我测试看看切换到MKOverlayLevelAboveLabels是否有所作为但遗憾的是结果是相同的.
有没有人有关于如何改进渲染的建议?切换到测地路径是否会产生影响?如果是这样,我将如何实现此目的?
此时,我正在试图弄清楚MKMapView上的坐标是否在提前绘制出的纬度/经度的MKPolygon内.
我正在使用CGPathContainsPoint来确定坐标是否在地图上的多边形内,但无论我选择哪个坐标,它总是返回false.
任何人都可以解释究竟出了什么问题?下面是我在Swift中的代码.
class ViewController: UIViewController, MKMapViewDelegate
@IBOutlet weak var mapView: MKMapView!
let initialLocation = CLLocation(latitude: 43.656734, longitude: -79.381576)
let point = CGPointMake(43.656734, -79.381576)
let regionRadius: CLLocationDistance = 500
let point1 = CLLocationCoordinate2D(latitude: 43.656734, longitude: -79.381576)
var points = [CLLocationCoordinate2DMake(43.655782, -79.382094),
CLLocationCoordinate2DMake(43.657499, -79.382310),
CLLocationCoordinate2DMake(43.656656, -79.380497),
CLLocationCoordinate2DMake(43.655782, -79.382094)]
override func viewDidLoad() {
super.viewDidLoad()
centerMapOnLocation(initialLocation)
let polygon = MKPolygon(coordinates: &points, count: points.count)
mapView.addOverlay(polygon)
var annotation = MKPointAnnotation()
annotation.coordinate = point1
annotation.title = "Test"
annotation.subtitle = "Test"
mapView.addAnnotation(annotation)
self.mapView.delegate = self
}
func …Run Code Online (Sandbox Code Playgroud) 我正在使用mapkit.我希望地图缩放以显示用户的位置和注释点,而不是仅缩放到用户的当前位置.
目前我有:
let annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2DMake(mapLat, mapLon)
annotation.title = mapTitle
self.map.addAnnotation(annotation)
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let userLoction: CLLocation = locations[0]
let latitude = userLoction.coordinate.latitude
let longitude = userLoction.coordinate.longitude
let latDelta: CLLocationDegrees = 0.05
let lonDelta: CLLocationDegrees = 0.05
let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta)
let location: CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
let region: MKCoordinateRegion = MKCoordinateRegionMake(location, span)
self.map.setRegion(region, animated: true)
self.map.showsUserLocation = true
}
Run Code Online (Sandbox Code Playgroud)
它只是缩放到用户的位置,它被锁定在该位置.当我尝试滚动时,它会直接跳回用户的位置.我究竟做错了什么?如何让用户在不跳回当前位置的情况下缩放或移动地图?
我正在尝试放大以在同一视图上显示注释和用户的位置.即使注释很远,我也希望它能够缩放以显示用户和注释.
在Google Maps API或iOS Mapkit中是否可以隐藏一个特定的街道标签?我已经做了很多研究,除了将谷歌地图样式化以隐藏所有街道名称标签之外,找不到方法.我可以对任何其他免费的Maps API开放,只要它可以集成在xCode/Swift/iOS中.
我已经集成MapKit在我的iOS应用程序中,并且无需在xCode/target/Capabilities中切换Maps即可正常工作.
那么,地图是否需要在功能中打开?
我刚刚发现了Capabilities,因为我需要切换In-App-Purchases.
MapKit中是否有专用按钮将摄像头集中在用户位置?或者我必须手动创建按钮和切换mapView.showsUserLocation = true吗?
当用户在地图上放大或滚动时,我想连续更新我的UI,根据MKMapView.(不仅在滚动结束后,工作正常.)
我尝试了委托方法mapView:regionWillChangeAnimated:根据文档,"只要当前显示的地图区域发生变化就会调用.在滚动期间,可以多次调用此方法来报告地图位置的更新." http://developer.apple.com/library/ios/#DOCUMENTATION/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
{
[self updateUIAcordingToMapViewRegionChange];
}
Run Code Online (Sandbox Code Playgroud)
但不幸的是,这不起作用,因为文档似乎没有说实话.该方法仅在区域变化的最开始时调用一次.在滚动期间,当手指向下并四处移动时,永远不会再次调用该方法.
我能找到的关于这个问题的唯一帖子是由macrumors成员namanhams:http://forums.macrumors.com/showthread.php?t = 1225172 但是没有人想出任何想法......
作为一种解决方法,我尝试在regionWillChange中设置一个计时器(并在regionDidChange中使其无效):
- (void)handleRegionChange:(NSTimer*)timer
{
[self updateUIAcordingToMapViewRegionChange];
}
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
{
self.mapRegionIsChangingTimer = [NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(handleRegionChange:)
userInfo:nil
repeats:YES];
}
Run Code Online (Sandbox Code Playgroud)
但这也行不通.来自计时器的所有方法调用都在滚动结束后立即执行.似乎滚动mapView阻止主线程或其他东西......
我也在stackoverflow上阅读了这篇文章,但遗憾的是并没有完全理解它: 监视MKMapView重绘事件 所以如果我的问题的解决方案确实存在于那个SO线程中,请告诉我,我试着深入研究它的细节.
我仍然希望我只是太愚蠢或太盲目无法找到正确的委托方法,并且非常感谢处理MKMapView区域跟踪的任何提示,变通方法和最佳实践.
谢谢!
ios ×10
mapkit ×10
swift ×4
google-maps ×2
mkmapview ×2
mkpolyline ×2
objective-c ×2
annotations ×1
ios7 ×1
map ×1
mkannotation ×1
mkoverlay ×1
mkpolygon ×1
uiimage ×1
xcode ×1