2011-05-14 24 views
0

我有一個的NSString這是一個地址:如何格式化此字符串以發送到Google Forward Geocoding?

"210 Queen Street East Brampton" 

我需要來ping谷歌的地理編碼服務器從這個字符串構造的URL需要看起來像這樣:

http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true_or_false 

很顯然,我可以追加串在一起,以創建一個主串 所謂的氣溫,然後就

使用此代碼來發送請求:

NSMutableString *url = [[NSMutableString alloc] initWithString:temp]; 

我面臨的挑戰是:如何在單詞之間引入'+'符號而不是空格?

任何人都可以建議,如果在目標C中的功能可以做到這一點或什麼是最好的方式來強有力地實現呢?

謝謝。

回答

0

我希望找到一些方法,可以讓你替換字符,但還沒有找到它。我能想到的迄今最簡單的解決辦法是以下幾點:

NSString *myAddress = @"210 Queen Street East Brampton"; // or whatever the current address is 
NSArray *components = [myAddress componentsSeparatedByString:@" "]; 
// this will strip the words out; 
NSString *addressForURL = [components componentsJoinedByString:@"+"]; 

這應返回addressForURL爲210 +大牀+街+東+賓頓。如果有更多你需要處理它,這應該至少給你一個基地,從

+0

偉大。這樣可行。非常感謝! – banditKing 2011-05-14 23:42:16

+0

沒問題,只是很高興幫助 – justin 2011-05-14 23:46:12

相關問題