objective-c谷歌静态地图返回零
这是我的代码:objective-c谷歌静态地图返回零,objective-c,google-maps,uiimage,Objective C,Google Maps,Uiimage,这是我的代码: #define GOOGLE_STATIC_MAP_IMAGE @"https://maps.googleapis.com/maps/api/staticmap?center=%@&zoom=15&size=320x150&maptype=roadmap&markers=color:green|label:H|%@" -(UIImage*)GetGoogleStaticMap { NSString* coordinates = [NSSt
#define GOOGLE_STATIC_MAP_IMAGE @"https://maps.googleapis.com/maps/api/staticmap?center=%@&zoom=15&size=320x150&maptype=roadmap&markers=color:green|label:H|%@"
-(UIImage*)GetGoogleStaticMap
{
NSString* coordinates = [NSString stringWithFormat:@"%f,%f", latitude, longitude];
NSString *stringURL = [NSString stringWithFormat:GOOGLE_STATIC_MAP_IMAGE, coordinates, coordinates]; //coordinates x2 = for the center & the marker
NSURL *url = [NSURL URLWithString:stringURL];
NSData *imageData = [[NSData alloc] initWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imageData];
return image;
}
如果我将stringURL粘贴到浏览器,我会得到所需的结果,但是imageData返回nil-ideas?由于字符串中的某些字符,它可能返回nil 在创建
url
对象之前,请尝试通过在stringURL
上使用incode:NSUTF8StringEncoding添加百分比转义来调用stringby
例如:
newStringURL = [stringURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];