我想在我的MKMapView
而不是小石头上显示图像.有人可以在这里放一些有用的代码,或告诉如何做到这一点?
谢谢!
编辑
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil ) pinView = [[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID];
pinView.pinColor = MKPinAnnotationColorGreen;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
pinView.image = [UIImage imageNamed:@"pinks.jpg"]; //as suggested by Squatch
}
else {
[mapView.userLocation setTitle:@"I am here"];
}
return pinView;
}
Run Code Online (Sandbox Code Playgroud)
我期待我的图像pinks.jpg在地图上,固定位置而不是默认的针视图(摇针形状).但我仍然得到了引脚的默认图像.
我有一个注释列表(MKPointAnnotation).我有一个UIViewController这是整个视图,执行的MKMapView控制,我认为是用于检测与地图,告诉您如何显示注释的用户互动,我自己MKPointAnnotation实现(子类)控制器有用.
然而,我对用户检测到轻敲事件感到震惊.
谷歌搜索告诉我,我必须通过实现以下功能来做一些事情.
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
Run Code Online (Sandbox Code Playgroud)
而且我必须在一些实现MapViewDelegate(协议)的类中实现它.
但我很困惑,无法前进.谁能告诉我在哪做什么?
抱歉所有的大惊小怪!
我removeAnnotations
用来删除我的注释,mapView
但同样删除用户位置ann.我该如何防止这种情况,或者如何让用户回来查看?
NSArray *annotationsOnMap = mapView.annotations;
[mapView removeAnnotations:annotationsOnMap];
Run Code Online (Sandbox Code Playgroud) 从iOS 7到8,我的代码运行良好.昨天更新了我的引脚上的自定义图像被标准引脚图像替换.有什么建议?
我的代码:
extension ViewController: MKMapViewDelegate {
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView! {
if annotation is MKUserLocation {
return nil
}
let reuseId = String(stringInterpolationSegment: annotation.coordinate.longitude)
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
if pinView == nil {
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.canShowCallout = true
pinView!.image = getRightImage(annotation.title!!)
}
let button = UIButton(type: UIButtonType.DetailDisclosure)
pinView?.rightCalloutAccessoryView = button
return pinView
}
}
Run Code Online (Sandbox Code Playgroud)
获取图像的函数UIImage
根据名称返回:
func getRightImage (shopName:String)-> UIImage{
var correctImage = UIImage()
switch shopName
{
case …
Run Code Online (Sandbox Code Playgroud) placemark = [[MKPlacemark alloc]initWithCoordinate:storedCoordinate addressDictionary:addressDict];
Run Code Online (Sandbox Code Playgroud)
我试图创建字典用于上面的代码,但没有任何作用:(
NSDictionary *addressDict = [[NSDictionary alloc] initWithObjectsAndKeys:
location.countryCode, @"CountryCode",
location.country,@"kABPersonAddressCountryKey",
location.state, kABPersonAddressStateKey,
location.city, @"City",
location.street, kABPersonAddressStreetKey,
location.zip, kABPersonAddressZIPKey,
nil];
Run Code Online (Sandbox Code Playgroud) 我有两个UITextField,用户可以在纬度和经度中输入,这些坐标然后用于在MKMapView上创建一个引脚.
我想找到一种方法来验证他们输入的值是实际的GPS坐标还是只是一堆垃圾.有没有办法做到这一点?
我想从我的mapview中删除所有注释,而不是我的位置的蓝点.我打电话的时候:
[mapView removeAnnotations:mapView.annotations];
Run Code Online (Sandbox Code Playgroud)
删除所有注释.
如果注释不是蓝点注释,我可以通过哪种方式检查(如所有注释的for循环)?
编辑(我用这个解决了):
for (int i =0; i < [mapView.annotations count]; i++) {
if ([[mapView.annotations objectAtIndex:i] isKindOfClass:[MyAnnotationClass class]]) {
[mapView removeAnnotation:[mapView.annotations objectAtIndex:i]];
}
}
Run Code Online (Sandbox Code Playgroud) 我想以MKPinAnnotationView
编程方式打开标注.例如,我在地图上放了10个针脚,想要打开离我最近的一个针脚.我该怎么做呢?
Apple已指定'selected'参数MKAnnotationView's
,但不鼓励直接设置(这不起作用,尝试过).
其余MKAnnotationView
只有一个setHighlighted(同一故事),并且可以ShowCallout
方法..
任何提示,如果这是可能的吗?
我正在使用MKMapView和MKAnnotationView.
我在地图上有一个注释.当用户点击它时,会显示callOut Bubble.再次点击注释(并且callOut Bubble可见)我需要更改为另一个视图.
如何检测第二个水龙头或气泡中的水龙头?
我想加入MKAnnotationView
,MKMapView
但我不能这样做......任何人都可以帮助我吗?
这是我的代码:
override func viewDidLoad() {
super.viewDidLoad()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
var latitude:CLLocationDegrees = locationManager.location.coordinate.latitude
var longitude:CLLocationDegrees = locationManager.location.coordinate.longitude
var homeLati: CLLocationDegrees = 40.01540192
var homeLong: CLLocationDegrees = 20.87901079
var latDelta:CLLocationDegrees = 0.01
var longDelta:CLLocationDegrees = 0.01
var theSpan:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta)
var myHome:CLLocationCoordinate2D = CLLocationCoordinate2DMake(homeLati, homeLong)
var myLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
var theRegion:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, theSpan)
self.theMapView.setRegion(theRegion, animated: true)
self.theMapView.mapType = MKMapType.Hybrid
self.theMapView.showsUserLocation = true
///Red Pin
var myHomePin = MKPointAnnotation()
myHomePin.coordinate = myHome
myHomePin.title …
Run Code Online (Sandbox Code Playgroud) mkannotation ×10
mkmapview ×8
ios ×5
mapkit ×3
objective-c ×3
iphone ×2
swift ×2
addressbook ×1
callouts ×1
coordinates ×1
geolocation ×1
gps ×1
ios5 ×1
ios9 ×1
userlocation ×1
xcode ×1