我在IB中定义了一个Map View,它被设置为显示用户位置.
在我的应用程序中,在-viewDidAppear中,我查询self.mapView.userLocation.location.coordinate并返回疯狂的值,例如:
纬度:4.8194501961644877e-49
经度:2.2993313035571993e-59
但是,下次调用-viewDidAppear时(在我简单地移动到另一个选项卡式视图然后再返回到此选项卡之后),userLocation属性将保留当前位置的正确值.
似乎在我的初始调用时,userLocation属性尚未初始化,但是尽管已经阅读了Apple的文档,但我看不出有任何警告,它表示此属性仅在执行xxx后才有效.
在userLocation有效使用之前是否有必要发生的事情,或者我应该只使用CLLocationManager来代替它吗?
在此先感谢您的帮助.
可悲的是,托马斯的建议并没有帮助.我发现的是:
如果showsUserLocation是NO,那么用户位置永远不会正确设置和-MapView:didUpdateUserLocation:不会被调用,所以我从来没有得到一个合理的位置值.
因此,要获取用户的位置,我必须将showsUserLocation设置为YES,然后这意味着在将所有注释添加到视图中后(不包括用户的位置),然后我计算所需的跨度以包含它们并显示它们一切都在正确的缩放级别.在我这样做之后,视图会向侧面跳跃,因为Map View会自动将用户的位置显示为蓝色斑点!因为它从未包含在注释中以计算缩放级别,所以我无法将其合并到我的计算中.Aaargh!
请注意,当showsUserLocation为YES时,则会调用-MapView:didUpdateUserLocation:,但只有在我计算了我的注释的所有坐标之后才会调用,而不是之前!
我想从plist中读取数据,添加一些元素并将数据写入plist.(更新plist).
我想让plist持有一个字典数组,将这个数组读入我的应用程序,添加字典然后将数组写回plist.
这是怎么做到的?我也不确定在应用程序首次启动时在何处以及如何创建plist.还是应该从一开始就放在捆绑中?
另一件我不确定的事情是,plist词典是否可以将CLLocations保存为键的值?它会被正确保存还是需要将CLLocation分解为lat和lon值?
谢谢
我有一个UITableView,每个单元格都包含一个Map按钮.当我点击每个按钮时,会显示地图视图并添加相应的注释引脚.
点击每个地图按钮时会调用此代码,
double tempLatitude = [[[myDict objectForKey:key] objectAtIndex:15] doubleValue];
double tempLongitude = [[[myDict objectForKey:key] objectAtIndex:16] doubleValue];
// key is the cell index.
//--** Setting the Latitude and Longitude
CLLocationCoordinate2D myCoordinate;
myCoordinate.latitude = tempLatitude;
myCoordinate.longitude = tempLongitude;
MyMapAnnotation *MyAnnotation = [[[MyMapAnnotation alloc] initWithCoordinate:myCoordinate addressDictionary:nil]autorelease];
MyAnnotation.title = [[myDict objectForKey:key] objectAtIndex:1];
MyAnnotation.subtitle = [NSString stringWithFormat:@"%f %f", MyAnnotation.coordinate.latitude, MyAnnotation.coordinate.longitude];
Run Code Online (Sandbox Code Playgroud)
这是MyMapAnnotation的代码,
@synthesize coordinate = theCoordinate;
@synthesize title = theTitleAnnotation;
@synthesize subtitle = theSubTitleAnnotation;
- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate addressDictionary:(NSDictionary *)addressDictionary
{
if ((self = [super initWithCoordinate:coordinate addressDictionary:addressDictionary]))
{ …Run Code Online (Sandbox Code Playgroud) 这是一个非常奇怪的问题,但我认为我可能还没有真正理解MapKit的细节.我在页面上有一堆注释.当我选择一个时,我想要一个标注出现.我有[pinView setCanShowCallout:YES];,我知道当我点击引脚时,它们被选中,因为相应的委托方法mapView:didSelectAnnotationView被触发了.但是,没有标注弹出!是什么赋予了?任何帮助是极大的赞赏.
我需要获取当前用户位置,但我不知道它是否已更改.我可以从CLLocationManager请求强制位置更新吗?或者还有其他方法吗?
我使用MKAnnotationView的自定义子类.在mapView:didSelectAnnotationView:我的Map委托的方法我调用这个类的方法,它将UIImageView与图像作为子视图添加 - 它作为我的自定义注释标注.
当使用默认的MKPinAnnotationView地图时,会自动调整地图区域以显示刚刚出现的注释标注.如何使用自定义MKAnnotationView子类实现此行为?
我需要地图上的圆圈周围填充空间与iOS7中的"提醒"应用程序相同.我认为需要使用方法applyFillPropertiesToContext:atZoomScale或fillPath:inContext:.

我正在将一个位置传递给另一个UIViewController有MapView使用的位置prepareForSegue.我叫这个receivedLocation.地图以传递的位置为中心.如果用户单击某个按钮将其带到地图而不先发送位置,这不会失败吗?
如何测试是否receivedLocation实际包含数据,以便我可以将地图设置为以其他内容为中心(如果它是空的)?
是否会创建一个布尔变量,并且最初将其设置为false,但在传递位置并按照我的意愿测试该工作时将其设置为true ?
我看到有一些叫做CLLocationCoordinateIsValid可用的东西,但它的参数是2DCoordinate,我遇到了同样的测试问题receivedLocation.
我对此很新,并试图寻找答案,但找不到合适的答案.谢谢!
import UIKit
import MapKit
import CoreLocation
class mapViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet var map: MKMapView!
@IBOutlet var notes: UITextView!
var receivedLocation = CLLocation()
var annotation = MKPointAnnotation()
var currentManager:CLLocationManager!
var latitute:CLLocationDegrees = CLLocationDegrees()
var longitude:CLLocationDegrees = CLLocationDegrees()
override func viewDidLoad() {
super.viewDidLoad()
map.layer.cornerRadius = 12.0
notes.layer.cornerRadius = 12.0
currentManager = CLLocationManager()
currentManager.delegate = self
currentManager.desiredAccuracy = kCLLocationAccuracyBest …Run Code Online (Sandbox Code Playgroud) 我添加了一个用户触摸此代码的引脚:
func addPin(tap: UITapGestureRecognizer) {
if (tap.state == UIGestureRecognizerState.Ended) {
var coordinate = mapView.convertPoint(tap.locationInView(mapView), toCoordinateFromView: mapView)
let address = addressAnnotationLogic.createWithCoordinate(coordinate)
mapView.addAnnotation(address)
routeLogic.addAddressAnnotation(address, toRoute: currentRoute!)
// reverse geocode
let pinLocation = CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude)
let geocoder = CLGeocoder()
geocoder.reverseGeocodeLocation(pinLocation!, completionHandler: {
(placemarks, error) -> Void in
if error != nil {
println("Reverse geocoder failed with error " + error.localizedDescription)
}
if placemarks.count > 0 {
let topResult = placemarks[0] as? CLPlacemark
self.addressAnnotationLogic.updateAnnotation(address, withPlacemark: topResult!)
}
})
}
}
Run Code Online (Sandbox Code Playgroud)
我的addressAnnotationLogic只是创建一个支持NSManagedObjectModel来保存它,我的routeLogic只是将它添加到另一个NSManagedObjectModel的路由中.我的委托方法非常标准.
func …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我有一个不同颜色的mapkit和注释.但是,只有三种颜色选项(红色,绿色,紫色).所以,我需要使用自定义图像更改注释.
现在,我有一个艺术作品课:
import Foundation
import MapKit
class Artwork: NSObject, MKAnnotation {
let title: String
let locationName: String
let color: String
let coordinate: CLLocationCoordinate2D
init(title: String, locationName: String, color: String, coordinate: CLLocationCoordinate2D) {
self.title = title
self.locationName = locationName
self.color = color
self.coordinate = coordinate
super.init()
}
var subtitle: String {
return locationName
}
// pinColor for disciplines: Sculpture, Plaque, Mural, Monument, other
func pinColor() -> MKPinAnnotationColor {
switch color {
case "Red":
return .Red
case "Purple":
return …Run Code Online (Sandbox Code Playgroud) mapkit ×10
ios ×7
iphone ×4
swift ×3
mkmapview ×2
objective-c ×2
annotations ×1
cocoa-touch ×1
ios7 ×1
location ×1
mkoverlay ×1
plist ×1