Scott Scott - 1 year ago 107
Swift Question

Xcode Swift - View entered Postcode on Apples map

i'm after for some help please!

I've got a textField called 'textFieldPostcode' and a

called 'btnViewOnMap'

my idea is that when the user enters their postcode into the
, and presses
button, it will take the user to Apples Built in maps and show the postcode that was entered.

I've seen a few tutorials on how to open Apples build-in Maps with code, which works


@IBOutlet weak var textFieldPostcode: UITextField?
@IBOutlet weak var btnViewOnMap: UIButton?


let tapGesture = UITapGestureRecognizer(target: self, action: #selector(viewOnMapPress))

Function for the viewOnMapPress:

func viewOnMapPress(sender: UITapGestureRecognizer){
if (buttonError != nil)
UIApplication.sharedApplication().openURL(NSURL(string: "")!)


the line below opens the maps, and shows a location, but how can i change this so that it searches for the users input instead ?

UIApplication.sharedApplication().openURL(NSURL(string: "")!)

Thanks in advance!

Answer Source

Try this (send postcode as query parameter to map):

let stringURLSearchPostCode = "" + self.textFieldPostcode.text
UIApplication.sharedApplication().openURL(NSURL(string: stringURLSearchPostCode)!)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download