ios - Accessing MKLocalSearchResponse item (swift) -
when println(localsearchresponse)
, mapitem object, includes ton of details location. in example, ucsd. here output showing in log.
<mklocalsearchresponse: 0x1c53d640> { boundingregion = "<center:+32.87514836, -117.23958822 span:+0.00725621, +0.00825332>"; mapitems = ( "<mkmapitem: 0x1c538090> {\n iscurrentlocation = 0;\n name = \"university of california, san diego\";\n phonenumber = \"+18585342230\";\n placemark = \"university of california, san diego, 9500 gilman dr, la jolla, ca 92093-5004, united states @ <+32.87529400,-117.23961000> +/- 0.00m, region clcircularregion (identifier:'<+32.87514837,-117.23958825> radius 557.57', center:<+32.87514837,-117.23958825>, radius:557.57m)\";\n url = \"http://www.ucsd.edu\";\n}" ); }
notice how outputs placemark = university of california...
, has address? how value , store variable? here code:
localsearchrequest = mklocalsearchrequest() localsearchrequest.naturallanguagequery = addresstextfield.text localsearch = mklocalsearch(request: localsearchrequest) localsearch.startwithcompletionhandler { (localsearchresponse, error) -> void in if localsearchresponse == nil{ var alert = uialertview(title: nil, message: "place not found", delegate: self, cancelbuttontitle: "try again") alert.show() return } //prints mklocalsearchresponse name, phonenumber, placemark println(localsearchresponse) //get latitude , longitude var newrecordlat = localsearchresponse.boundingregion.center.latitude var newrecordlong = localsearchresponse.boundingregion.center.longitude //how address, "placemark" in mklocalsearchresponse? var newrecordaddress = localsearchresponse.mapitems...??? //store values parse self.lattoparse = newrecordlat self.longtoparse = newrecordlong }
here documentation of mksearchresponse
and here documentation of mkmapitem
the answer is:
var newrecordaddress = (localsearchresponse.mapitems[0] as! mkmapitem).placemark
this object contains information need. checked in demo project
address only:
var newrecordaddress = (localsearchresponse.mapitems[0] as! mkmapitem).placemark let addressonly = newrecordaddress.name + ", " + newrecordaddress.title
newrecordaddress.name
place's name newrecordaddress.title
place's address required
Comments
Post a Comment