How to make link open "Maps" window when clicked - iphone

I would like to have a link in a web page in such a way that when the link is clicked it opens the standard "Maps" view in iPhone.
If such a thing is possible, what tag format do I need to use with the link?

It's pretty simple; you don't even need to use a specific scheme identifier. Any Google Maps URL will be opened with the Maps app automatically, as long as all the parameters are supported.
So links like these:
http://maps.google.com/maps?q=cupertino
http://maps.google.com/maps?daddr=San+Francisco,+CA&saddr=cupertino
Would automatically be opened in Maps. To find out more about what works and what doesn't see the Map Links page from the Apple URL Scheme Reference.

I used this code which works passing longitude lattitude:
NSString *url = [NSString stringWithFormat: #"http://maps.google.com/maps?saddr=%f,%f&daddr=%#",cur_lat, cur_lon,[loc stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(#"current %f %f",cur_lat,cur_lon);
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:url]];

Related

How to make an url page compatible for iPhone UIWebView in objective c

I have built an application for iPhone.
In this app I need to use an url in the UIWebView.
I have implemented like this
NSString *urlAddress = #"http://chat.stackoverflow.com/faq";
// Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
// URL Request Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
// Load the request in the UIWebView.
[documentsWebView loadRequest:requestObj];
The problem is that the web site is shown using zoom factor 100%. Hence my users have to scroll both vertically and horizontally. How do I adjust the zoom factor so that only vertical scrolling is required per default?
It sounds to me like you want to turn on:
documentsWebView.scalesPageToFit = YES;
On UIWebView there are many settings: enable/diable zoom, javascript, there are to many, better check documentation for that.
Your problem solution will be a server side html coding. There you need to check the client, his resolution and such.
Pls check in google "responsive layout" for html page.
No we cannot. It's web-server side check.
From the web-server side it required to check which client browser is being used (using user-agent).
Accordingly server will navigated to specific page or load css.
There is nothing required from device-end.

OpenURL to a file in NSBundle

I have a file, which i want to open in safari (or call it view in safari).
I add this file to my bundle resources.
and do the following:
NSString *path = [[NSBundle mainBundle] pathForResource:#"tryFile.txt" ofType:nil inDirectory:nil];
NSURL *url = [NSURL fileURLWithPath: path];
NSLog(#"path: %# \n url:%# \n can open url:%d",path,url,[[UIApplication sharedApplication] canOpenURL:url]);
BOOL didGo = [[UIApplication sharedApplication] openURL:url];
NSLog(#"didgo?: %d",didGo);
Of course, as the sandboxed environment says, I am not able to open the file ins safari. It says, canOpenURL as yes but then didGo is NO.
How can I do this without setting up a local server. Please suggest.
Should I keep the data stored in a variable and then open an html page with that data...or what?
EDIT:
These are the logs:
path: /var/mobile/Applications/C78C7CD8-22C7-468A-AA5D-AF22C6042378/TryApp.app/tryFile.txt
url:file://localhost/var/mobile/Applications/C78C7CD8-22C7-468A-AA5D-AF22C6042378/TryApp.app/tryFile.txt
can open url:1
didgo?: 0
PLEASE NOTE opening the file in a webview is not an option. The requirement wants it to be opened in safari. And anyways, this example is of a text file...the filethat may be opened can be anything, and webview does not support all file types.
The txt file resides within your application sandbox. The URL that you are trying to load in Safari will not get loaded due to security in iOS. Read more about it here
As a workaround you can use a UIWebView in your application and open the file in that.
Cheers!Amar.
You'll need to setup a server or open the page in a UIWebView inside the app.
NSString *path = [[NSBundle mainBundle] pathForResource:#"tryFile.txt" ofType:nil inDirectory:nil];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:path]];
This code is for open url in directly in safari OR you can use Webview and direct open url in your webview.thanks

Open Twitter app in html

Is there anyway to open the twitter app from an html link on an iPhone? Kind of how when you click a youtube link it goes to the youtube app.
thanks
You'd use twitter:// as the URL and put it in an action for a button or something like so:
-(IBAction)openTwitter{
NSURL* url = [NSURL URLWithString:#"twitter://"];
[[UIApplication sharedApplication] openURL:url];
}
If you meant html on a website you'd use tap me to go to twitter for the link.
URL Schemes are shown here and you can grab some more handy information about them too.
I'd probably recommend #Arab_Geek's solution though as it isn't that much of a trouble and it's giving back control to the user.
Why don't you use Twitter integratation for iOS 5 (TWTweetComposeViewController) ?
NSURL * twitterURL = [NSURL URLWithString:#"twitter://"];
if([[UIApplication sharedApplication] canOpenURL:twitterURL])
[[UIApplication sharedApplication] openURL:twitterURL];

UIApplication OpenUrl double-escaping my URLs

Basically, i'm trying to program a "tweet this" button from inside my application. Depending on their spot in the application, they can click the tweet button and it'll shoot them out to Safari with a tweet message that changes depending on where they are.
In order to create URLs, I have to escape the query string that I want to put in the NSUrl object. So, I do this:
NSString* escapedTweet = [#"Some String With Spaces" stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
After concatenating the base, my url comes out "http://www.twitter.com/home/?status=Some&20String%20With%20Spaces" - looked at it in the debugger and this is definitely the value (as expected). Now, I create my URL and launch safari:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:escapedUrlString]];
But here's where the issue comes up: OpenUrl appears to be escaping my percent signs, so the actual URL that Safari goes to is "http://www.twitter.com/home/?status=Some%2520String%2520With%2520Spaces", which is obviously a problem since twitter creates the status message as "Some%20String%20With%20Spaces".
NSUrl will NOT allow me to create a URL with spaces in it, so i'm completely lost as to how to get my URLs to just include a %20. Has anyone else run into this issue or found a workaround?
I'm running on an iPad with an up to date OS, not sure if it's the same issue on the iPhone.
Edit: In a nutshell, how do I get openUrl to open http://www.twitter.com/home/?status=Some%20Url%20With%20Spaces without escaping my percent signs and creating a URL like http://www.twitter.com/home/?status=Some%2520Url%2520With%2520Spaces?
I am assuming that escapedUrlString is declared as NSURL *escapedUrlString = [NSURL URLWithString:escapedTweet];. Then your problem probably lies in openURL:[NSURL URLWithString:escapedUrlString]];, because you’re taking an URL, passing it into another URL and then opening it. Fix by passing in escapedURLString (which should be named ‘escapedURL’) instead of URLWithString:….

Mapping data from RSS feed with no latitude/longitude using MapKit

Having follow the tutorial at http://mithin.in/2009/06/22/using-iphone-sdk-mapkit-framework-a-tutorial/ to integrate the MapKit into my application. However, I want to be able to display an annotation for a dynamic "incident" on the map. Here's where I'm having problems.
Basically my apps an RSS reader, and it downloads everything and saves each item of the feed (as in Story 1, Story 2) as currentItem. The data I want to grab and use to map the annotation can be found under currentItem.title - but I can't seem to get it to work in this tutorial's code or find the right place to put it.
The RSS feed I'm using doesn't have any latitude/longitude information either - making it even harder.
Any help would be great - I've been working on this for a couple of days now with still no luck.
UPDATE: I'm even considering launching the Google Maps application instead showing the annotation. But this in itself is raising issues. Below is the code I'm using but its throwing errors everywhere.
NSString *title = currentItem.title;
int zoom = 13;
NSString *stringURL = [NSString stringWithFormat:#"http://maps.google.com/maps?q=%##%1.6f,%1.6f&z=%d", title, zoom];
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
In the end I just mapped the title using reverse lookup, and added the country afterwards so results would only be in the country where the address is. Not ideal, but it seems to work OK.