在Swift编程中将urlpath添加到NSUrl时获取nil

时间:2014-07-18 08:19:46

标签: ios map swift

mapServerRequest =“Midtown,New York,NY,USA”

var mapAddress:NSString=mapServerRequest

     println(mapAddress)
var urlpath=NSString(format: "http://maps.googleapis.com/maps/api/geocode/json?address=%@", mapAddress)
     println(urlpath)
var url = NSURL.URLWithString(urlpath)
    println(url)

1 个答案:

答案 0 :(得分:2)

您应该对mapAddress进行URL编码:

mapAddress.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLPathAllowedCharacterSet())