我有一个MKAnnotationView被分配了一个DetailDisclosure按钮显示在注释的右侧.我怎么知道用户何时点击了注释按钮?这就是我的代码现在的样子 -
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.rightCalloutAccessoryView = rightButton;
pinView.animatesDrop = YES;
Run Code Online (Sandbox Code Playgroud)
是否有内置方法来检测附件视图何时被触摸?我猜它会像UITableView方法,但我找不到任何东西.谢谢你的帮助.
我无法弄清楚为什么当前的位置圈不会出现.我有自定义注释看起来很好......并且地图被带到用户的当前位置......但是,圆圈没有出现.
这是我的代码.提前致谢!
- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];
[mapView setMapType:MKMapTypeStandard];
mapView.showsUserLocation = YES;
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.span.longitudeDelta = 0.005;
region.span.latitudeDelta = 0.005;
[mapView setRegion:region animated:YES];
[mapView setDelegate:self];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
CLLocationCoordinate2D loc = [newLocation coordinate];
[mapView setCenterCoordinate:loc];
}
-(MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString *AnnotationViewID = @"annotationViewID";
MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID]; …Run Code Online (Sandbox Code Playgroud) 好的,这实际上是一个线程中的三个不同的问题:
1)我正在使用:
- (void)viewDidLoad
{
[super viewDidLoad];
[mapView setFrame :CGRectMake(-100,-100,520,520)];
[mapView setAutoresizesSubviews:true];
mapView.showsUserLocation = YES;
locManager = [[CLLocationManager alloc] init];
locManager.delegate = self;
[locManager startUpdatingLocation];
[locManager startUpdatingHeading];
[bt_toolbar setEnabled:YES];
}
- (IBAction) CreatePicture
{
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(mapView.userLocation.coordinate.latitude, mapView.userLocation.coordinate.longitude);
CGPoint annPoint = [self.mapView convertCoordinate:coord toPointToView:self.mapView];
mapPic = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pic.png"]];
mapPic.frame = CGRectMake(annPoint.x, annPoint.y, 32, 32);
[self.view addSubview:macPic];
}
Run Code Online (Sandbox Code Playgroud)
使用GCRectMake在用户的坐标上放置图像,但遗憾的是图像没有放在正确的位置:

如果我移动地图,图片将始终放置与用户位置完全相同的偏移量.我错过了什么?它不应该直接放在用户上方吗?我猜测偏移量(-100,-100)我首先给出了mapView是导致这种情况的原因(我在下方有一个工具栏,因此偏移).
2)我的iOS 5模拟器表现得很疯狂,把我的位置放在凤凰城的格伦代尔(不应该是在Cupertino吗?)出于某种原因,并且因为我正在向东移动; 我的iPhone 4一切正常(除了不正确的图片放置).有任何想法吗?
3)我一直在考虑使用Annotations,但我听说它们是静态的(我真的需要它们是动态的).这是真的?
谢谢!
我在用户点击图钉时显示自定义UIView(如Zillow应用程序).现在的问题是我需要将视图放在实际引脚的正上方.MKAnnotationView坐标系与地图相关.如何获取iPhone屏幕的坐标,然后将我的视图放在该坐标上.
- (void)mapView:(MKMapView *)mv didSelectAnnotationView:(MKAnnotationView *)view
{
// get view from storyboard
ZillowSearchResultAnnotation *annotation = (ZillowSearchResultAnnotation *) view.annotation;
PropertyAbstractViewController *propertyAbstractViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PropertyAbstractIdentifier"];
propertyAbstractViewController.view.frame = CGRectMake(0, 0, 100, 100);
[propertyAbstractViewController bind:annotation.data];
[mv addSubview:propertyAbstractViewController.view];
}
Run Code Online (Sandbox Code Playgroud) 试图让用户选择在我的应用程序中选择谷歌地图(sdk)和苹果地图(mapkit).该应用程序没有使用ARC.崩溃场景(ios 6.0/6.1):1.进入谷歌地图(模态控制器).2.退出谷歌地图(解雇模态).3.将我的应用程序更改为apple maps(mapkit).4.输入apple maps(模态控制器).
应用程序崩溃,我得到:[EAGLContext setCurrentContext:]
如果我不在dealloc中释放谷歌地图,则不会发生错误,但它可能会导致内存泄漏.我在viewDidLoad中保留地图并在dealloc中释放地图.
有人可以帮忙吗?谢谢,Tomer
1 0x0a041324 in -[VGLGPU init] ()
2 0x0a041032 in __24+[VGLGPU sharedInstance]_block_invoke_0 ()
3 0x03b52014 in _dispatch_client_callout ()
4 0x03b4409f in dispatch_once_f ()
5 0x03b44061 in dispatch_once ()
6 0x0a040fef in +[VGLGPU sharedInstance] ()
7 0x09fab26b in -[VKMainLoop updateLinkState] ()
8 0x09fabb02 in -[VKMainLoop removeCanvas:] ()
9 0x09f9f2aa in -[VKScreenCanvas _updateDisplayStatus:] ()
10 0x09f9f3fb in -[VKScreenCanvas setNeedsDisplay] ()
11 0x027bc03d in -[UIView initWithFrame:] ()
12 0x09f75658 in -[VGLScreenCanvas initWithFrame:context:] ()
15 0x09f907e7 …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序拨打电话获取用户的位置:
-(void)getLocation{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
//SET USER LOCATION
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
self.userLocation = [locations lastObject];
NSLog(@"location in IntroVC %f, %f", self.userLocation.coordinate.latitude, self.userLocation.coordinate.longitude);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,因为NSLog无限地吐出一个新的位置,我何时应该停止呼叫该位置?嗯,我想它真的取决于我的应用程序的功能,但这不会导致电池耗尽吗?如果是这样,我应该真正研究停止更新的最佳方法.
我在地图上显示了一些注释(某些点),地图放大或缩小以适合所有点 - 请参阅下面的工作代码.
MKPolygon *poly = [MKPolygon polygonWithPoints:somepoints count:i];
[self.mapView setRegion:MKCoordinateRegionForMapRect([poly boundingMapRect]) animated:NO];
Run Code Online (Sandbox Code Playgroud)
问:我想略微扩展这个多边形以获得一些余量,我该如何扩大这个区域?
这是我之前的帖子,我将图像设置为注释视图引脚
现在我遇到了在注释视图图像上设置圆角的问题.
cannot show callout with clipsToBounds enabled swift
Run Code Online (Sandbox Code Playgroud)
似乎我必须在圆角或显示标注之间做出选择,我真的不明白为什么这两个不能出现.有没有办法做到这一点?这是我的viewForAnnotation函数:
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if !(annotation is RestaurantAnnotation) {
return nil
}
let reuseId = "restaurant"
var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if anView == nil {
anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
anView.canShowCallout = false
}
else {
anView.annotation = annotation
}
let restaurantAnnotation = annotation as RestaurantAnnotation
if (restaurantAnnotation.image != nil) {
anView.image = restaurantAnnotation.image!
anView.layer.masksToBounds = true
anView.layer.cornerRadius = (anView.frame.size.height)/10.0
} …Run Code Online (Sandbox Code Playgroud) 我知道几年前就已经问过这个问题了,但所有答案都涉及到使用Google Maps API来解决这个问题.我想知道是否有一种正确的方法可以解决这个问题,因为iOS8已经出局,它为本机MapKit带来了许多改进.
基本上我在路上画了一条折线,它由许多中间点组成.
var locations = [CLLocation]()
for item in list {
locations.append(CLLocation(latitude: CLLocationDegrees(item["location"]["coordinate"]["x"].doubleValue), longitude: CLLocationDegrees(item["location"]["coordinate"]["y"].doubleValue)))
}
var coordinates = locations.map({(location: CLLocation!) -> CLLocationCoordinate2D in return location.coordinate})
var polyline = MKPolyline(coordinates: &coordinates, count: locations.count)
mapView.addOverlay(polyline)
Run Code Online (Sandbox Code Playgroud)
地图上有5到30个点.当折线连接它们时,我或多或少地得到了旅行的公平表示.问题是:它不会坚持到路上.

所以我不时会有"粗糙"的边缘.即使我使用的是Google Direction API,它也只限于8个方向点,并且基本上决定了如何从A点到B点,沿途绘制平滑折线.此外,Directions API限制为每24小时2500次使用.我需要做的就是将当前的折线调整到最近的道路
非常感谢
这是我第一次在这里发帖.我目前陷入困境,试图找出如何在我的地图上添加一个按钮,如果他们在地图上偏离它,将重新显示用户的当前位置.目前我有下面写的代码显示用户的当前位置.
import UIKit
import MapKit
import CoreLocation
class GameViewController: UIViewController,CLLocationManagerDelegate
{
var lastUserLocation: MKUserLocation?
@IBOutlet weak var Map: MKMapView!
let manager = CLLocationManager()
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations[0]
let span:MKCoordinateSpan = MKCoordinateSpanMake(0.00775, 0.00775)
let myLocation: CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude,location.coordinate.longitude)
let region: MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span)
Map.setRegion(region, animated: true)
self.Map.showsUserLocation = true
manager.stopUpdatingLocation()
}
override func viewDidLoad() {
super.viewDidLoad()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestAlwaysAuthorization()
manager.startUpdatingLocation()
}
@IBAction func refLocation(_ sender: Any) {
print("click") …Run Code Online (Sandbox Code Playgroud) mapkit ×10
ios ×7
iphone ×4
objective-c ×3
swift ×3
mkannotation ×2
xcode ×2
ios4 ×1
ios5 ×1
mkpolygon ×1
mkpolyline ×1