Retrieve image from Google Maps in iOS - ios

Im trying to attach a Google Maps image to an email generated in my app, however Google Maps does not return a specific image from its url. If I search a url with .png etc at the end of it, I can get the image fine, but how can I get the image from a site that doesn't have that,
ie:
http://maps.googleapis.com/maps/api/staticmap?size=200x200&maptype=roadmap\\&markers=size:mid%%7Ccolor:red%%7CNew+York&sensor=false
Im using NSData dataWithContentsOfURL: which then attaches to my email.
I have also tried to open the url in an iframe within the email with the same result, works with a .png url, not maps.
Any help would be greatly appreciated, thanks.

Try this,
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;

http://maps.googleapis.com/maps/api/staticmap?size=200x200&maptype=roadmap%%5C&markers=size:mid%%257Ccolor:red%%7CNew+York&sensor=false
Just needed to edit some of the % \ etc to incorporate the UTF8 encoding, however if you use the encoding method karthika suggested, it breaks the search. All I did was hard code the string and removed the added encoding before the address and its working perfectly.

Related

image are not showing on imageview. in ios

http://hauwengweb.azurewebsites.net/api/AccomodationImages/images/1
I'm trying to download image on imageView. If you will paste this url on browser it will show, but on imageView it's not showing. If you will try any other image, then the same code will work, but when I used this url, the image does not show.
The image in question seems to be a WebP image (served with the wrong MIME type of image/png), which is not a format natively supported by UIImage. However, you can use iOS-WebP to decode the image:
Add the framework, header and implementation to your project, then use:
#import "UIImage+WebP.h"
NSURL *url = [NSURL URLWithString:#"http://hauwengweb.azurewebsites.net/api/AccomodationImages/images/1"];
NSData *data = [NSData dataWithContentsOfURL:url];
imageView.image = [UIImage imageWithWebPData:data];
And please remember to do the download and decoding steps asynchronously so as not to block the main UI.
Try this?
NSURL *url = [NSURL URLWithString:#"http://hauwengweb.azurewebsites.net/api/AccomodationImages/images/1"];
NSData *data = [NSData dataWithContentsOfURL:url];
self.img.image = [UIImage imageWithData:data];
Edit
The URL you provided is not an absolute path hence the data being fetched cannot be converted into an UIImage. There is something wrong with the URL or the formatting of it.

Pass an Url to image view through AFNetworkingLibrary

The project was created with xcode 4.3.
I have used AFNetworking Library (non-ARC) in this app.
NSURL *url = [NSURL URLWithString:urlstring];
[exhibitPortraitImageView setImageWithURL:url];
Here, when I print a NSLog value, am getting the URL but the imageview is not displayed.
How can I solve this?
Your code is fine, problem is with URL.
Your URL, don't have prefix, http://, I added it and the code is same as in quesiton.
NSString *urlstring = #"http://mdb.scicloudsolutions.com:8001/sites/default/files/genesis-book-of-beginnings.jpg";
NSURL *url = [NSURL URLWithString:urlstring];
[exhibitPortraitImageView setImageWithURL:url];
Here, you've three options to fix this,
1) If URLs are not coming from server (or some where else) you can fix it within the app, see how,
NSString *badUrlString = #"mdb.scicloudsolutions.com:8001/sites/default/files/genesis-book-of-beginnings.jpg";
NSString *goodUrlString = [NSString stringWithFormat:#"http://%#",badUrlString];
2) Or if its coming from server (or some where else) you can ask them to fix this from their side.
3) If its under 2nd option then, ask them if this will always happen (static) then you can also modify this from your side if server side developers not able to fix.
see this for more help, Check string containing URL for "http://"
Yes,
I also tried your url, it is working fine.
I loaded it as:
NSURL *correctURL = [NSURL URLWithString:#"http://mdb.scicloudsolutions.com:8001/sites/default/files/genesis-book-of-beginnings.jpg"];
_imgFromUrl.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:correctURL]];
And the result,

Can't display BLOB image in iOS application

I'm trying to display a BLOB image (get from web server using Json) in my iOS app, but when I run my application I get an empty UIimageView, here is my code :
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:encodedUrl]];
NSData *profileImage1 = [[NSData alloc] initWithBytes:[dataURL bytes] length:[dataURL length]];
UIImage *profileImage2 = [UIImage imageWithData:profileImage1];
[profilImage setImage:profileImage2];
How can I fix this problem?
[UIImage imageWithData:data] only parses known image file formats like JPEG, PNG, etc. (Full info in the decomentation). Passing blobs isn't supported by UIImage. You need to do some decoding to be able to use the data for the UIImage. You can use GMTBase.64 for encoding and decoding of data. Read the docs and other posts and you'll find out how to change your code.
Hope this helps.

How can I get user avatar link of facebook with userid

I have id of user on facebook. Now I want to get user avatar base on the link https://graph.facebook.com on iOS.
Try to use via this link :
https://graph.facebook.com/user_id/picture?type=normal
Hope this works.
As i also gave you the first comment so explaining it.
If you looking the Avatar link try
http://graph.facebook.com/username/picture
where you can try the username like sunnyleone or you can use the facebook userid like for sunnyleone the userid is 131218490419638.
if you looking your facebook id you can get it from here. for your examples.
And One Major thing that nobody checked Image size is small for you can add parameter like
?type=normal
or for more bigger image. But the best one is you can replace the redirect link like.
replace _s to _n
Small Image :
http://profile.ak.fbcdn.net/hprofile-ak-prn1/t5/162024_131218490419638_623017319_s.jpg
Big Image : http://profile.ak.fbcdn.net/hprofile-ak-prn1/t5/162024_131218490419638_623017319_n.jpg
then you can get the bigger Image.
Hope this will help you
use #"https://graph.facebook.com/uid/picture" to get facebook profile picture
NSString *urlStr = [NSString stringWithFormat:#"http://graph.facebook.com/%#/picture?type=large", userId];
NSURL *url = [NSURL URLWithString:urlStr];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];

Random URL website address from core data that holds a picture to display in UIImage in iOS?

I'm new to using xcode, so any information or links would be helpful. If I had a RANDOM website url in coredata, how would I be able to direct my UIImage to get the photo from that website to display in iOS?
Let's say imageURL is a NSString * ivar or property where you hold your URL.
To get the image this should work:
NSURL *url = [NSURL URLWithString:imageURL];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *myImage = [UIImage imageWithData: imageData];
Of course you should add some error checking but this should get you into the right direction.

Resources