Load google static map in UIImageView?

I am trying to show a small google static map in my application. I am wondering if this can be done using UIImageView? This doesn't seem to work for me, but maybe I'm doing something wrong.

This is what I have (I removed the url to make it easier to read):

NSURL *mapurl = [[NSURL alloc]    initWithString:@"http://maps.google.com/maps/api/staticmap?[...]"]; 
NSData *mapdata = [[NSData alloc] initWithContentsOfURL:mapurl];
UIImage *uimap = [[UIImage alloc] initWithData:mapdata];
self.map.image = uimap; // map is my UIImageView    
[mapurl release];   
[mapdata release];
[uimap release];

I know that my UIImageView is configured correctly, because if I replace the URL with one of the images, it will load normally. I also know that the Google Maps URL is correct, because if I download it directly to the browser, it displays normally.

I am starting to think that this may be impossible. If anyone has any ideas or alternatives, please share.

Thank.

+3
1

, , , - .

NSURLConnection. , , . URL- " URL-". , URL google, .

, URL-, :

// The URL you want to load (snipped for readability)
NSString *mapurl = @"http://maps.google.com/maps/api/staticmap?[...]";  

// Escape the string
mapurl = [mapurl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

, , NSURLConnection, . , , .

+4

Source: https://habr.com/ru/post/1747202/


All Articles