2013-10-01 22 views
0

我試圖將Google地圖圖像附加到在我的應用中生成的電子郵件中,但Google地圖不會從其url中返回特定圖像。如果我在它的結束搜索與巴紐等一個網址,我可以得到圖像細膩,但我怎樣才能從一個網站的形象,不具有,從iOS中的Google地圖中檢索圖像

即:

http://maps.googleapis.com/maps/api/staticmap?size=200x200&maptype=roadmap\\&markers=size:mid%%7Ccolor:red%%7CNew+York&sensor=false 

我使用NSData dataWithContentsOfURL:然後附加到我的電子郵件。

我也嘗試在電子郵件中的iframe中打開相同結果的url,使用.png url而不是maps。

任何幫助將不勝感激,謝謝。

回答

0
http://maps.googleapis.com/maps/api/staticmap?size=200x200&maptype=roadmap%%5C&markers=size:mid%%257Ccolor:red%%7CNew+York&sensor=false 

只需要編輯一些%\等納入UTF8編碼,但是如果你使用的編碼方法karthika建議,它打破了搜索。我所做的全部都是硬編碼字符串,並在地址及其工作完美之前刪除了添加的編碼。

1

試試這個,

NSString *urlString = @"http://maps.googleapis.com/maps/api/staticmap?size=200x200&maptype=roadmap\\&markers=size:mid%%7Ccolor:red%%7CNew+York&sensor=false"; 
NSString *encodedString=[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
NSURL *webURL = [NSURL URLWithString:encodedString]; 
NSData *myData = [NSData dataWithContentsOfURL:webURL]; 
UIImage *image = [[UIImage alloc] initWithData:myData]; 
self.imageView.image = image; 
+0

這是非常接近完美,除了編碼打破搜索。它返回的圖像,我可以附加它,但它的世界,而不是具體的位置。有任何想法嗎? –

+0

+1的幫助,如果沒有你的意見,你是不會想出來的。謝謝 –