我制作了一个地图App,首先打开时会显示MapView并有各种注释。
我现在正在尝试在MapView的角落添加一个信息页面(一点点" i"按钮,就像地图注释一样),以便转到另一个视图,其中包含对应用程序的简要说明
我该怎么做呢? 我已经尝试将一个按钮直接放在MapView的顶部,但它似乎只是删除了MapView并将按钮居中。这是由于我的Segue从MapView注释信息按钮到各自的信息页面吗?
感谢您的帮助。
答案 0 :(得分:0)
@IBOutlet var mapView: GMSMapView!
let baseURLGeocode = "https://maps.googleapis.com/maps/api/geocode/json?"
var lookupAddressResults: Dictionary<NSObject, AnyObject>!
var fetchedFormattedAddress: String!
var fetchedAddressLongitude: Double!
var fetchedAddressLatitude: Double!
override func viewDidLoad() {
super.viewDidLoad()
//Setup our Location Manager
let address = storeAddress.text
self.geocodeAddress(address, withCompletionHandler: { (status, success) -> Void in
if !success {
print(status)
if status == "ZERO_RESULTS" {
print("location not found")
}
}
else {
let coordinate = CLLocationCoordinate2D(latitude: self.fetchedAddressLatitude, longitude: self.fetchedAddressLongitude)
let camera = GMSCameraPosition(target: coordinate, zoom: 15, bearing: 0, viewingAngle: 0)
//self.mapview.camera = camera
//self.mapview.animateToCameraPosition(camera)
//let mapView = GMSMapView.mapWithFrame(CGRect.zero, camera: camera)
self.mapView.camera = camera
self.mapView.animateToZoom(18)
self.mapView.setMinZoom(15, maxZoom: 25)
self.mapView.mapType = kGMSTypeTerrain;
self.mapView.delegate=self;
let marker = GMSMarker()
marker.position = camera.target
marker.snippet = address
marker.appearAnimation = kGMSMarkerAnimationPop
marker.map = self.mapView
let circ = GMSCircle.init(position: marker.position, radius: 50)
circ.fillColor = UIColor.blackColor().colorWithAlphaComponent(0.2)
circ.strokeColor = UIColor.redColor()
circ.strokeWidth = 1
circ.map = self.mapView
//self.viewMap.camera = GMSCameraPosition.cameraWithTarget(coordinate, zoom: 14.0)
}
})
self.overlay = AlertView.init(frame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height))
}
func geocodeAddress(address: String!, withCompletionHandler completionHandler: ((status: String, success: Bool) -> Void)) {
if address == ""
{
completionHandler(status: "No valid address.", success: false)
}
else if let lookupAddress = address {
var geocodeURLString = baseURLGeocode + "address=" + lookupAddress
geocodeURLString = geocodeURLString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!
let geocodeURL = NSURL(string: geocodeURLString)
dispatch_async(dispatch_get_main_queue(), { () -> Void in
let geocodingResultsData = NSData(contentsOfURL: geocodeURL!)
//let json = try! NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments) as! NSDictionary
let dictionary: Dictionary<NSObject, AnyObject> = try! NSJSONSerialization.JSONObjectWithData(geocodingResultsData!, options: NSJSONReadingOptions.AllowFragments) as! Dictionary<NSObject, AnyObject>
// Get the response status.
let status = dictionary["status"] as! String
if status == "OK" {
let allResults = dictionary["results"] as! Array<Dictionary<NSObject, AnyObject>>
self.lookupAddressResults = allResults[0]
// Keep the most important values.
self.fetchedFormattedAddress = self.lookupAddressResults["formatted_address"] as! String
let geometry = self.lookupAddressResults["geometry"] as! Dictionary<NSObject, AnyObject>
self.fetchedAddressLongitude = ((geometry["location"] as! Dictionary<NSObject, AnyObject>)["lng"] as! NSNumber).doubleValue
self.fetchedAddressLatitude = ((geometry["location"] as! Dictionary<NSObject, AnyObject>)["lat"] as! NSNumber).doubleValue
completionHandler(status: status, success: true)
}
else {
completionHandler(status: status, success: false)
}
})
}
else {
completionHandler(status: "No valid address.", success: false)
}
}