我正在做以下事情,总是得到绿色的针脚:
pin.pinColor = MKPinAnnotationColorRed;
[self.mapView addAnnotation:pin];
[pin release];
Run Code Online (Sandbox Code Playgroud)
pin的类型为"NSObject".所有引脚都是绿色的.我应该采用不同的方式吗?
当引脚完成它的放置动画时,我希望弹出注释标注.目前我可以使用以下方法模拟它:
- (void)showCallOut {
[myMapView selectAnnotation:[myMapView.annotations objectAtIndex:0] animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
在我viewDidLoad的地方创建了我的注释
[myMapView addAnnotation:annotation];
Run Code Online (Sandbox Code Playgroud)
问题是你之后根本无法[self showCallOut];调用,因为在运行时它会在MapKit"确认"注释掉落之前做出响应.我需要创建一个延迟(想要避免这种情况)或者找到正确的方法来检测注释何时就位,然后运行该showCallOut方法.
谢谢你的帮助!
感谢下面的aBitObvious提供解决方案:
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
[self performSelector:@selector(showCallOut) withObject:nil afterDelay:1];
}
Run Code Online (Sandbox Code Playgroud) 我正在使用MapKit api获取地图上的当前位置,并在两个位置指针之间绘制路线.我还希望获得其路线之间的所有主要站点.我使用下面的函数来获取两个位置之间的路由
- (NSArray*)getRoutePointFrom:(MyLocation*)origin to:(MyLocation*)destination
{
NSString* saddr = [NSString stringWithFormat:@"%f,%f", origin.coordinate.latitude, origin.coordinate.longitude];
NSString* daddr = [NSString stringWithFormat:@"%f,%f", destination.coordinate.latitude, destination.coordinate.longitude];
NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%@&destination=%@&sensor=false&avoid=highways&mode=driving",saddr,daddr]];
NSError *error=nil;
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:url];
[request setHTTPMethod:@"POST"];
NSURLResponse *response = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error: &error];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
SBJsonParser *json=[[SBJsonParser alloc] init];
NSDictionary *dic=[json objectWithString:responseString error:nil];
NSDictionary *nextdic=[dic valueForKey:@"routes"];
NSDictionary *legdic=[nextdic valueForKey:@"legs"];
NSDictionary *stepdic=[legdic valueForKey:@"steps"];
NSArray *array=[[NSArray alloc] initWithArray:[[stepdic valueForKey:@"polyline"] valueForKey:@"points"]];
NSString …Run Code Online (Sandbox Code Playgroud) 我想在地图上显示地图和绘制路线.我的应用程序支持ios 4 plus.那么我应该如何使用地图来处理ios 6以及之前的工作.另外我想知道sholud我在我的应用程序中使用自定义mapview来显示地图和路线,或者我应该使用
[[UIApplication sharedApplication] openURL:]
Run Code Online (Sandbox Code Playgroud)
我从来没有用过MapKits.所以请提供任何教程.如果有任何可以使用的rd方库,请告诉我.
我想设置一个MKPointAnnotation,当它被点击时,我可以调用另一个功能.反正有没有添加手势识别器或类似的东西?
我正在尝试找到一种使用MapKit在地图上显示用户方向的方法。MapKit的本机方法总是旋转整个地图。由于用户位置也是MKAnnotationView,因此我决定创建一个特定的类来覆盖它并使用特定的图像(带有箭头)。
class UserLocationAnnotationView: MKAnnotationView {
override init(frame: CGRect) {
super.init(frame: frame)
}
override init(annotation: MKAnnotation!, reuseIdentifier: String!) {
super.init(annotation: annotation, reuseIdentifier: reuseIdentifier)
var frame = self.frame
frame.size = CGSizeMake(130, 130)
self.frame = frame
self.backgroundColor = UIColor.clearColor()
self.centerOffset = CGPointMake(-30, -50)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
*/
override func drawRect(rect: CGRect) {
// Drawing code
UIImage(named: "userLocation.png")?.drawInRect(CGRectMake(65, 65, …Run Code Online (Sandbox Code Playgroud) 我是新手Swift,我尝试了这个
不知道为什么此代码不起作用:
//start mehtod out of scope
lazy var locationManager: CLLocationManager! = {
let locationManager = CLLocationManager()
//configeration for user location access
//The delegate object to receive update events.
locationManager.delegate = self
//The receiver does its best to achieve the requested accuracy
//locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.distanceFilter = 10.0
//Requests permission to use location services while the app is in the foreground
locationManager.requestWhenInUseAuthorization()
//allow update notification when apps stay on background
locationManager.allowsBackgroundLocationUpdates = true
return locationManager
}()
Run Code Online (Sandbox Code Playgroud)
当我设置时它工作正常: …
我从MKLocalSearchCompleter收到MKLocalSearchCompletion项目给它的委托.每个MKLocalSearchCompletion都包含一个标题和一个副标题,副标题是一个地址.我需要从地址中提取一个城市和一个国家.请帮忙!
因此,在更新到Xcode 10和Swift 4.2时,我当然必须在项目中进行很多更改以更新语法。除了一个问题,我能够解决所有问题。我收到一条错误消息:'MKMapRectIsNull'已由属性'MKMapRect.isNull'代替。我也试图替换明显的事情MKMapRectIsNull与MKMapRect.isNull,但其产生的另一个错误,说:实例成员“的isNull”不能在类型“MKMapRect”使用。这里是一些更多的上下文:
var zoomRect = MKMapRect.null
for annotation in map.annotations {
let annotationPoint = MKMapPoint(annotation.coordinate)
let pointRect = MKMapRect(x: annotationPoint.x, y: annotationPoint.y, width: 0, height: 0)
if (MKMapRect.isNull(zoomRect)) {
zoomRect = pointRect
} else {
zoomRect = zoomRect.union(pointRect)
}
}
map.setVisibleMapRect(zoomRect, edgePadding: UIEdgeInsets(top: 40, left: 40, bottom: 40, right: 40), animated: true)
Run Code Online (Sandbox Code Playgroud)
任何想法/帮助将不胜感激。