How to display address in google map application in iphone - iphone

I have loaded google map application in iphone . I am using UIWebView Control in that Control i loaded google maps like following
UIWebView *webView;
NSString *url = [NSString stringWithFormat: #"http://maps.google.com/maps?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA"];
NSURL *aURL = [NSURL URLWithString:url];
webView.backgroundColor = [UIColor whiteColor];
NSURLRequest *aRequest = [NSURLRequest requestWithURL:aURL];
webView.dataDetectorTypes=UIWebViewNavigationTypeBackForward;
webView.scalesPageToFit = YES;
webView.autoresizesSubviews = YES;
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
//set the web view and acceleration delagates for the web view to be itself
[webView loadRequest:aRequest];
Its work fine with pin point.But i want to display address in google maps application when they click the pin.The pin (i.e its denoted A).
Can anyone help me ?
Thanks in advance......
One more help What i given in the parameters of " q " should be applied in the search box of google maps.I want to avoid this . Any help would be appreciated ?

use MapKit (MKMapView object) instead of a webview pointed to a google map image and use Google Map API to retrieve coordinates of the address.
You can use AddressAnnotation object to create a pin and the addAnnotation method of MKMapView to add it to your map.
Have fun !

Related

How to make a text in a label as url, to move to webpage / make a call by click on a text in a label

In my application I have displayed some content in a tableview with custom cell.
Custom cell having an imageView, button, 4 labels
Each label for
1. Name of the candidate
2. Web page address,
3. Email address
4. Phone number.
In this I need to highlight the web address label , phone number label and email address label like url's and to do respective actions when user touch them.
like
1. open web page when touch on web address label,
2. open email composer sheet when touch on email address label,
3. make a call when touch on phone number label
It's pretty much all the same idea, all applications in iOS can be opened with using the format appShortName://whatyouwantToHandle, for websites its just http://myurl
To make a call, it's tel:
NSURL *phoneURL = [NSURL URLWithString:#"tel:+123456789"];
[[UIApplication sharedApplication] openURL:phoneURL];
To start composing an email, it's mailto:, and it supports GET parameters to fill-out the email.
const NSString* mailFormat = #"mailto:%#?subject=%#&body=%#";
const NSString* mailEmails = #"person1#gmail.com,person2#gmail.com";
const NSString* mailBody = #"This is the mail body\n Hi!");
const NSString* mailSubject = #"This is the mail Subject!";
NSString *urlString = [NSString stringWithFormat:(NSString*)mailFormat,[mailEmails stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[mailSubject stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[mailBody stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURL *mailURL = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:mailURL];
And to open the web page, as you'd expect, it's just http:
NSURL *websiteURL = [NSURL URLWithString:#"http://mywebsite.com"];
[[UIApplication sharedApplication] openURL:websiteURL];
Check the documentation on -openURL: if you want to know more.
Make all UILabel's user interaction enabled. Apply tap gesture on each label and implement function call on tap of each label. Implement functions for each label suggested as above.

Which way is faster to load page in uiwebview

Which way is faster to load webpages in uiwebivew
using
Loading NSData into a UIWebView
OR
using Load Request URL?
Network requests take time. There's no point in trying to optimize a few milliseconds off this type of code. Write the code that is most readable / maintainable and it will serve you better.
You could put the webpage, scripts, css, and images in your app bundle; get a URL that points to it (file://...) and use that. Within your webpage, you can use AJAX to pull in some dynamic data, etc.
That'd be a better path to optimize; but it all depends on your situation.
If you have the option of using loadRequest, I'd recommend it. Let the OS take the work off your hands.
edit:
PS: UIWebView tends to take it's time about displaying data; even when no network is involved.
I often set the webview's alpha to 0 in IB or viewDidLoad; then fade it in when the content is ready.
Inside your webViewDidFinishLoad: method, add this:
if (0.0f == webview.alpha) {
[UIView animateWithDuration:0.4f
animations:^{
webview.alpha = 1.0f;
}];
}
Their is really isn't any "technical" way to load Webview faster, But I would recommend you use:
Load Request URL
Load Request URL Code:
#interface WebViewController : UIViewController {
IBOutlet UIWebView *webView;
}
#property (nonatomic, retain) UIWebView *webView;
#end
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)viewDidLoad {
NSString *urlAddress = #"http://www.google.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Request Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
}

how to add pinch and zoom on a uiwebview - iphone

I know this question has been asked a couple of times before. I m trying to zoom in / out the uiwebview. How exactly do i do this? I tried setting 'webView.scalesPageToFit=YES;' but its not working.
I also tried this How do I enable the zoom in/out option in a UIWebView? but yet im not able to achieve the zoom in / out
Code
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"%#",[actorUrlArray objectAtIndex:_rowNumberInActivity]]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
webView.scalesPageToFit=YES;
what am i missing out here?
NOTE : I'm loading the iphone app on the ipad to check the app. Can that be a problem??
If its the meta tag problem. how do i set them? i tried this code.. but its not working.. i know nothing about javascript.. so im not sure whether this is correct or not..
NSString* js =
#"var meta = document.createElement('meta'); \" \"meta.setAttribute( 'name', 'viewport' ); \" \"meta.setAttribute( 'content', 'width = device-width, initial-scale = 5.0, user-scalable = yes' ); \" \"document.getElementsByTagName('head')[0].appendChild(meta)";
[webView stringByEvaluatingJavaScriptFromString: js];
Zooming in and out and Pinch are built in feature of UIWebView. You don't need to write any code to achieve that.
just simply set the property.
scalesPageToFit=YES
for any pinching and zooming to work on a UIWebView

problems showing the actual URL of a page in my app

I'm making an iPad browser, and I have a little problem. When I go to google, for example, I write the google direction in a textField. The problem is that when I change the web page, it still says http://www.google.com/. Here's my code:
-(IBAction)buttonpressed2:(id)sender {
url = [NSURL URLWithString:[textField text]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[webView isEqual:textField.text];
}
How can I make the textField show the page that I'm watching right now, and not the first url typed in the field?
First, make sure when you set up the webView, you assign the UIWebViewDelegate to self
Then, implement the delegate method: webViewDidFinishLoad, as such:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSURLRequest *currentRequest = [webView request];
NSURL *currentURL = [currentRequest URL];
//This will log the current url
NSLog(#"Current URL is %#", currentURL.absoluteString);
//Then to display it in the textField
textfield.text = currentURL.absoluteString;
}
Edit:
A delegate is a special set of methods that wait for an event to happen. When that event happens, the appropiate method is called. The method above is one of the delegate methods for a UIWebView - When a specific event happens with the webView, in this case when the webViewDidFinishLoad, that method is automtically called and we can respond as such. In order to set the delegate, we can proceed one of two ways:
If you created the webView in code, this is with something like this:
UIWebView *webView = [[UIWebView alloc] init...]
then all you need to do is add the following line of code:
webView.delegate = self;
However, you might have also created the webView in the interface builder - If that's the case, click on the webView and the linker tab, and drag the delegate option over to "File's Owner".
and thats it.
Your class should implement the UIWebViewDelegate protocol. Then in the method webView:shouldStartLoadWithRequest:navigationType: you can do this:
[textField setText:[[request URL] absoluteString]];
This way the value in the textField will be updated whenever you navigate to a new url.

entity nbsp not defined

I have been trying to load the url http://friscotxcoc.weblinkconnect.com/cwt/External/WCPages2/wcevents/eventsstartpage.aspx?oe=true&ce=true into a webview but it shows up an error 'Entity nbsp not found'.
The link works properly over Safari (Machine as well as simulator) but doesnt load properly when loaded through a webview. Can someone point me as to how to do it?
#define kEventsCalenderLink #"http://friscotxcoc.weblinkconnect.com/cwt/External/WCPages2/wcevents/eventsstartpage.aspx?oe=true&ce=true"
NSURL *eventsURL = [NSURL URLWithString:kEventsCalenderLink];
eventsWebView.delegate = self;
[eventsWebView loadRequest:[NSURLRequest requestWithURL:eventsURL]];
The server is serving that page with the Content-Type of "application/xhtml+xml" to the Simulator version of Safari. Safari is interpreting the page as strict XML, which does not have an entity.
Unfortunately, UIWebView manipulates its HTTP headers behind the scenes, and it's seemingly impossible to configure it to make a request that will cause your server to serve content as "text/html"
The one workaround I would suggest is to retrieve the content with an NSURLConnection, then feed it to your web view with the loadData:MIMEType:textEncodingName:baseURL: method, being sure to pass "text/html" as the MIME type.
This may also necessitate intercepting future requests via the webView:shouldStartLoadWithRequest:navigationType: delegate method (in order to cancel them and load them in the manner described above to prevent similar problems).
Or, if you have control of the server, you could configure it to serve HTML with the appropriate content type. Or convert the content to use proper XML entities.
Do it in this way:
NSString *kEventsCalenderLink #"http://friscotxcoc.weblinkconnect.com/cwt/External/WCPages2/wcevents/eventsstartpage.aspx?oe=true&ce=true"
NSLog(#"%#",kEventsCalenderLink);
eventsWebView.delegate = self;
eventsWebView.userInteractionEnabled = true;
[eventsWebView loadRequest:[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:kEventsCalenderLink]]];
You have only defined the URL which you haven't mentioned that it's string type.
Here is the sample code which i implemented.Hope it would help you
- (void)loadView
{
UIView *vew=[[UIView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
self.view=vew;
//self.title=#"sanjay";
//self.navigationItem.title=#"afdsfasd";
self.view.backgroundColor=[UIColor redColor];
[vew release];
UIButton *smsbtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
smsbtn.frame=CGRectMake(50, 280, 100, 50);
[smsbtn setTitle:#"SMS APP" forState:UIControlStateNormal];
[smsbtn setTitleEdgeInsets:UIEdgeInsetsZero];
[smsbtn addTarget:self action:#selector(loadsms) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:smsbtn];
}
-(void)loadsms
{
NSString *url = [NSString stringWithFormat:#"http://friscotxcoc.weblinkconnect.com/cwt/External/WCPages2/wcevents/eventsstartpage.aspx?oe=true&ce=true"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: url]];
}
This code is working dude.Try this out.I have implemented this for you only.