Skip to content

Instantly share code, notes, and snippets.

@mitsuse
Last active June 23, 2016 05:38
Show Gist options
  • Save mitsuse/76b0cd79b353a0c1c5abc3ba140907b1 to your computer and use it in GitHub Desktop.
Save mitsuse/76b0cd79b353a0c1c5abc3ba140907b1 to your computer and use it in GitHub Desktop.
A workaround for iOS 8.x, which cannnot use `q` parameter as the label of pin. (Swift 2.2)
import Foundation
public func buildMapUrl(
latitude latitude: Double,
longitude: Double,
label: String
) -> NSURL? {
let components = NSURLComponents(string: "http://maps.apple.com/")
if #available(iOS 9, *) {
components?.queryItems = [
NSURLQueryItem(
name: "ll",
value: "\(latitude),\(longitude)"
),
NSURLQueryItem(name: "q", value: label),
]
} else {
components?.queryItems = [
NSURLQueryItem(
name: "q",
value: "\(latitude),\(longitude)"
),
]
}
return components?.URL
}
@mitsuse
Copy link
Author

mitsuse commented Jun 23, 2016

The query. This parameter is treated as if its value had been typed into the Maps search field by the user. Note that q=* is not supported
The q parameter can also be used as a label if the location is explicitly defined in the ll or address parameters.

https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html (Updated: 2015-06-08)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment