I´m trying to open street view in UIWebView but it doesn´t work. I can see just normal maps. How can I solve it? Any other possibilities?
that´s my code:
NSString *urlAddress = #"http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=bran+castle&sll=44.439972,26.096894&sspn=0.000869,0.003664&ie=UTF8&hq=Bran+Castle&hnear=Bran+Castle,+Strada+General+Traian+Mo%C8%99oiu+nr.+28+E574,+Bran+507025,+Romania&t=k&layer=c&cbll=45.516381,25.368123&panoid=0d7jjq7vdWGTxFyonEKnBQ&cbp=12,209.81,,1,-18.52&ll=45.516381,25.368123&spn=0,0.008444&z=17";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webV loadRequest:requestObj];
Try loading this code for your UIWebview:
NSString *latLongString =[NSString stringWithFormat:#"%f,%f", latitude, longitude];
[_uiWebView loadHTMLString:[NSString stringWithFormat:#"<html><head><meta name='viewport',user-scalable=no'/><script src='http://maps.google.com/maps/api/js?sensor=false'type='text/javascript'></script></head><body onload=\"new google.maps.StreetViewPanorama(document.getElementById('p'),{position:new google.maps.LatLng(%#)});\" style='padding:0px;margin:0px;'><div id='p' style='height:100%%; width:100%%;'></div></body></html>",latLongString] baseURL:nil];
No. U can't achieve this .
see here
but u can like this
http://maps.google.com/?q=Tokyo#35.680,139.769
u can pass this link to ur webview to load it.
see here
Does MapKit allow for StreetView?
Simply Run the Google map url request in your webView and in webViewDidFinishLoad method add this below line to hide alert.
webView.stringByEvaluatingJavaScriptFromString("document.getElementsByClassName('ml-unsupported-link-dialog-container')[0].style.display='none'")
Here is a sample call to load Google StreetView in UIWebView. I used Swift.
let urlAddress = "http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=bran+castle&sll=44.439972,26.096894&sspn=0.000869,0.003664&ie=UTF8&hq=Bran+Castle&hnear=Bran+Castle,+Strada+General+Traian+Mo%C8%99oiu+nr.+28+E574,+Bran+507025,+Romania&t=k&layer=c&cbll=45.516381,25.368123&panoid=0d7jjq7vdWGTxFyonEKnBQ&cbp=12,209.81,,1,-18.52&ll=45.516381,25.368123&spn=0,0.008444&z=17";
let request = NSURLRequest(URL: NSURL(string: urlAddress)!)
glWebView.loadRequest(request)
Related
I inspect the YouTube page in Google Chrome and noticed that in the player div there is video element with this id : player_VIDEOID.
And i want to get the src Attribute from this video element.
So i load UIWebView with this:
NSURL *url = [NSURL URLWithString:#"http://m.youtube.com/watch?v=bnVUHWCynig"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[web loadRequest:requestObj];
And in - (void)webViewDidFinishLoad:(UIWebView *)webView
I implement a function in javascript that extract this src link with:
[web stringByEvaluatingJavaScriptFromString:#"var script = document.createElement('script');"
"script.type = 'text/javascript';"
"script.text = \"function myFunction() { "
"var videoele = document.getElementById('player_bnVUHWCynig');"
"var url = videoele.getAttribute('src');"
"return url;"
"}\";"
"document.getElementsByTagName('head')[0].appendChild(script);"];
NSString * t = [web stringByEvaluatingJavaScriptFromString:#"myFunction();"];
And t always equal to empty string.
I try to run this JS function in Chrome and url is the src link in the video element.
What i did wrong in this method??
I had used following code in my app but it opens new window and shows route fromcurrent location to destination.
code:
NSURL *url = [NSURL URLWithString:urlAddress];
[[UIApplication sharedApplication] openURL:url];
NSString *urlString = [NSString stringWithFormat:#"http://maps.apple.com/maps? daddr=%f,%f&saddr=%f,%f",12.8400,77.6700, 12.9610850,77.604692699999990];
NSString *escapedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url=[NSURL URLWithString:escapedString];
[[UIApplication sharedApplication]openURL:url];
but my requirement is to show route from current location to destination location without launching any url.
You need to request a directions for example from Google
http://maps.googleapis.com/maps/api/directions/json?origin=%f,%f&destination=%f,%f&sensor=true&mode=%#&departure_time=%ld
And then get the routes from received json and write the path on the map.
I think you could use a WebView and load that url in it.
You can use UIWebView and load the above URL in it
NSString *urlString = [NSString stringWithFormat:#"http://maps.apple.com/maps? daddr=%f,%f&saddr=%f,%f",12.8400,77.6700, 12.9610850,77.604692699999990];
NSString *escapedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url=[NSURL URLWithString:escapedString];
[webveiew loadRequest : [NSURLRequest requestwithURL:url]];
Use google maps api. Go through their documentation. Its helpful. I had used it in my application.
in the new safari on the mac they have a bar that can distinguish between google and a url.Thats what i am trying to do. I am wondering what i am doing wrong. It only wants to google not search url. Thanks in advance.
-(IBAction)SearchAll:(id)sender
{
if (googlebar) {
NSString *query = [googlebar.text stringByReplacingOccurrencesOfString:#" " withString:#"+"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.google.co./search?q=%#", query]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
}
else{
NSString *query = [googlebar.text stringByReplacingOccurrencesOfString:#" " withString:#"+"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.%#", query]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
}
}
Firstly, your code is way off. You will not achieve your goal this way.
Secondly, You should start off your IBAction statement by checking if the string that was input into the search bar (or urlbar whatever you want to call it) has a prefix of .com or .org...etc. If it does not then it then google searches the text in the UITextfield.
are you sure of your if statement?
you're using searchbar in the else, where searchbar if supposed not to exist.
you should also check the google.co./search url. I'd use google.com/search as it will save you a redirect
I'm still confused by your question though, as you have two toolbars: searchbar and googlebar, not one as in the latest safari for mac
I am currently trying to find a solution to this task. Essentially I have an initial UIView that asks for the users username and password for a specific site, this information would then get past onto the next view which has a UIWebView inside. I would like to know if its possible to automatically fill in the username and password details on the site and send the user directly to their account page on the site.
Thanks.
assuming your website has div tags you can inject using stringByEvaluatingJavsScriptFromString.
This example injects a username into the twitter sign up page. You can test it by loading this in your viewDidLoad:
NSString *urlString = #"https://mobile.twitter.com/signup";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
and then in webViewDidFinishLoad inject the username:
- (void)webViewDidFinishLoad:(UIWebView *)webView;
{
[webView stringByEvaluatingJavaScriptFromString:#"var field = document.getElementById('oauth_signup_client_fullname');"
"field.value='yourUserName';"];
}
sorry, just realised you already had the solution but were missing the implementation. Hope the above helps.
btw to add a dynamic variable into the injected javascript use:
- (void)webViewDidFinishLoad:(UIWebView *)webView;
{
NSString *injectedVariable = #"userNameHere";
NSString *injectedString = [NSString stringWithFormat:#"var field = document.getElementById('oauth_signup_client_fullname'); field.value='%#';", injectedVariable];
[webView stringByEvaluatingJavaScriptFromString:injectedString];
}
on solution is to "fake" the login request using the username and password and feed this into the web view.
I.e. you have a page index.php which has a username and password field.
if you fill them in, the page login.php is called with those parameters.
you could build an
NSString *urlString = #”http://www.yoursite.com/login.php?username=user&password=pass”;
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
that should do the trick
I am trying to build an RSS reader for the Tom's Hardware website.
I have an error when I try to load an URL into an UIWebview from an RSS link.
Here'is my code:
- (void)viewDidLoad {
[super viewDidLoad];
if (self.url != nil) {
NSURL *requestUrl = [NSURL URLWithString:self.url];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:requestUrl];
[webView loadRequest:requestObj];
}
}
The url is setted by the parent controller.
When the URL comes directly from the RSS, I have an error in log:
[2234:207] Error Domain=WebKitErrorDomain Code=101 UserInfo=0x3a6a240 "Operation could not be completed. (WebKitErrorDomain error 101.)"
When I set manually the URL with the same URL like below, it work !
self.url = #"http://www.presence-pc.com/tests/fraude-financiere-paget-macafee-23198/#xtor=RSS-12";
Here is an URL exemple: http://www.presence-pc.com/tests/fraude-financiere-paget-macafee-23198/#xtor=RSS-12. I have no idea about that problem.
I hope you can help me.
Best regards.
Thanks guy, that'it, I have split the URL like this:
NSArray *split = [url componentsSeparatedByString:#"#"];
NSURL *requestUrl = [NSURL URLWithString:[[split objectAtIndex:0] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
and now it work , thanks for your help !
I have this code which also triggers error code 101
_request = [NSURLRequest requestWithURL:[NSURL URLWithString:redirectUrl]];
[editorWebView loadRequest:_request];
RedirectURL is an NSString which has this format http%3A%2F%2Fwww.linkedin.com%2Fnhome%2F
I tried removing percent escapes using the method of NSString and it now works.
[redirectUrl stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
I think the problem can be the anchor in your URL, a friend got the same problem