Google map Implementation in Iphone - iphone

I already implemented google mapping functionality in my iphone application.It works fine but if the location to search is wrong string then it maps a location and it redirects to current location only after the search button clicks. How to implement that if the location is wrong then directly go to the current location? My code is like below
NSString *urlString = [[NSString stringWithFormat:#"http://maps.google.com/maps?z=14&q=%#",message] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
please give me a solution as soon as possible
Thanks in advance

Since you lose control the moment you leave your app, you should always perform the validity check before opening the URL by passing message to a CLGeocoder or a 3rd party Geocoder .
CLGeocoder Class Reference
Basically query for the location string inside your app, then format your url accordingly.

Related

How to register an app to respond to a custom URL scheme opening request?

Like this:
NSString *stringURL = #"appname://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
I slightly remember it was necessary to write a value-key to Info.plist. How?
Add this to plist .
The app will by called by #"readtext://" url
This seems to be the question that I answered (with screenshots & source code) here.
And I've posted a full walkthrough of how to do this on my blog.

How to return to my iphone application after call ends?

I am able to call from my iphone application by using below code:
NSString *phoneNumber = #"tel://1234567890";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Now, i want to know how to return to my application back when the call ends ?
UIWebView *phoneCallWebview = [[UIWebView alloc] init];
// [self.view addSubview:phoneCallWebview];
NSURL *callURL = [NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", 9238928399]];
[phoneCallWebview loadRequest:[NSURLRequest requestWithURL:callURL ]];
As far as I'm aware, such interaction is impossible since your application has been demoted to background, and all UI interaction has been delegated to the Phone app, and the user.
I found this SO question
End call, don't return to app automatic in iphone 3.1 version
Which pointed to an article on apple dev forums
https://devforums.apple.com/message/128046 (dev account required)
Which says it was a change in iOS 3.1 but a "workaround" is
use UIWebView to open the tel: url, after the call, your app will relaunch, but you get the annoying do you want to make this call alert.
I have't verified this works as described, just thought I'd point it out
From iOS 5, use below...
NSString *phoneNumber = [#"telprompt://" stringByAppendingString:#"12345678"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Just use telprompt:// instead of tel://
telprompt will prompt the user first, and when call ends,it will go back to your application.
NSString *myNumber = [#"telprompt://" stringByAppendingString:txtMobileNo.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:myNumber]];

Iphone: how to launch a route in google maps api from your application

I have read a lot of topics, but i don't find when i want
I want to launch google map api from my application with that:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"http://maps.google.com/maps?saddr=41.029598,28.972985&daddr=41.033586,28.984546"]]
But it's open safari with Google maps page. I want open Google map API with my route. There is a maps:// or other things?
Thanks for help !!!
Try this
UIApplication *app = [UIApplication sharedApplication];
NSURL *url = [[NSURL alloc] initWithString: #"http://maps.google.com/maps?saddr=41.029598,28.972985&daddr=41.033586,28.984546"];
[app openURL:url];
[url release];
have a look at the Apple URL Scheme Reference for MapLinks
Edit: your URL looks correct. Looks like you are testing on Simulator! GoogleMaps app is only available on device!
Try this
NSString *urlstring=[NSString stringWithFormat:#"http://maps.google.com/?&saddr=%# &daddr=%#",sourceaddress,destinationaddress];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlstring]];

Calling Card Integration in iPhone

I need to develop an application to integrate calling card functionality. The application will have an access number, a country code and a pin number setting.
When a user wants to make a call the system should dial the access number and then after a time interval it should dial the country code and finally pin number followed by the actual telephone number.
How would one implement this?
Might work, haven't tried it. Won't work in simulator. Real answer s/b close
UIApplication *app = [UIApplication sharedApplication];
NSString *urlString = [NSString stringWithFormat:#"te1://12125551212,,,%#,,,%#", numLang, numPin];
NSURL *url = [NSURL URLWithString:urlString];
[app openURL:url];
Comma are pauses.

iPhone: Open a url Programmatically

I am new to iPhone.
I want to open an url in my application.
How can I do this task? Please suggest me and provide some useful link.
Apparently the link given above is outdated. Here is the update link for the UIApplication class.
The quick and simple code snippet is:
// ObjC
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"http://www.google.com"]];
// Swift
UIApplication.shared.open(URL(string: "http://www.google.com")!, options: [:], completionHandler: nil)
Update (2016): The best way to do this nowadays is to instantiate and present an SFSafariViewController. This gives the user the security and speed of Safari, and access to any cookies or Safari features they may already have set without having to leave your app.
If you want to open the URL in Safari (and exit your application) you can use the openURL method of UIApplication
If you'd rather have it handled inside of your app, use WKWebView.
If you would like to open and just get the data from the URL, you could use NSString:
NSString *ans = [NSString stringWithContentsOfURL:url];
If what you are trying to get is an XML from a URL, you can directly use NSXMLParser:
NSURL *url = [[NSURL alloc] initWithString:urlstr];
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
// parse here
[parser release];
[url release];
On the other hand, if by opening you mean, open a URl in an embedded browser, you could use UIWebView class.
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"https://medium.com/the-traveled-ios-developers-guide/swift-3-feature-highlight-c38f94359731#.83akhtihk"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://medium.com/the-traveled-ios-developers-guide/swift-3-feature-highlight-c38f94359731#.83akhtihk"]];
}
else{
[SVProgressHUD showErrorWithStatus:#"Please enable Safari from restrictions to open this link"];
}