Open a map URL with MapKit - iphone

I was wondering how can I open a google map URL with MapKit ?
this code exit the application and shows the location but I want shows on my mapView.
NSString *urlString = #"http://maps.google.com/maps?daddr=San+Francisco,+CA&saddr=cupertino";
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: urlString]];

MapKit supports Geolocation - so how about something like this:
CLLocation *sanFran = [CLLocation locationUsingForwardGeoLocation:#"San Francisco, Califronia"];
This returns a CLLocation which you can then show on your map view.
Have a look at the World Cities sample code (iOS dev membership required) which shows how to animate an MKMapView to coordinates.
Edited to add
There are ways to get the Lat-long with Google Tools. You can use these to create a CLLocation as well.

You can use UIWebview to load the contents of the url. Create a webView and initialise as follows:
NSString *urlString = #"http://maps.google.com/maps?daddr=San+Francisco,+CA&saddr=cupertino";
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString: urlString]];
[webView loadRequest:req];
Yeah you should add this webview as a subview to your main view.

Related

Displaying a route from current location to destination location without launching any url in iOS

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.

Open PDF In iBooks

I've a a pdf placed in my Code files. I want it to open in iBooks, while researching I've found this :
NSString *stringURL = #"itms-books:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
NSString *stringURL = #"itms-bookss:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
How can I use this or what other way i can open my PDF File in iBook?
Regards
Maybe too late but I created a small example where the method explained in andycodes used. I uploaded to Github and you can download it here:
https://github.com/cjimenezpacho/openpdfibooks
Basically is this piece of code in a IBAction and the required delegate methods:
NSURL *url = [[NSBundle mainBundle]
URLForResource: #"iPhoneintro" withExtension:#"pdf"];
self.docController = [UIDocumentInteractionController interactionControllerWithURL:url];
self.docController.delegate = self;
[self.docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
Links to Apple documentation:
Class:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDocumentInteractionController_class/Reference/Reference.html
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"itms-bookss://%#",self.pathToFile]]];
this does open a local pdf to Ibooks needs 2 s's.
Edit: to be specific on this this will open the local PDF if it is in iBooks already locally on the device.
if you need to add it to iBooks so far as I know you need to use the UIDocumentInteractionController.
Take a look at this Tumblr post explaining how do achieve a similar result using UIDocumentInteractionControllers.
http://andycodes.tumblr.com/post/738375724/ios4-sdk-opening-pdfs-in-ibooks

How to open Google Street View in UIWebView?

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)

How do you default to walking directions when you open a google maps URL?

Currently I am doing this to 'get directions':
NSString *googleMapsURLString;
googleMapsURLString = [NSString stringWithFormat:
#"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f",
curLoc.latitude, // Start
curLoc.longitude,
self.hotspot.coordinate.latitude,
self.hotspot.coordinate.longitude];
NSLog(#"Opening URL: %#",googleMapsURLString);
NSURL *url = [NSURL URLWithString:googleMapsURLString];
[[UIApplication sharedApplication] openURL:url];
Does anyone know if there is a parameter to get directions via walking instead of defaulting to driving?
Just add
dirflg=w
to your parameters.

How to open Maps app from my code to show directions?

HI.. I have to show directions between two coordinates. I'd like to open Maps app, passing the start and end coordinates from my code.
I don't want to open it in the Google maps, which opens in browser(Safari). I tried that method. That was working perfect.
NSString* urlStr = [NSString stringWithFormat: #"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", s_lat, s_long, d_lat, d_long];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:urlStr]];
But, I want to open iPhone Maps app. How can i do this? Is this possible? Any help will be appreciated.
Try it on a real device. I'm using the same code and it opens Safari at the simulator and iPhone Maps at the device.
Hey Simon the method you are using is
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:urlStr]];
will only open safari.So there is no chance that with open url you would open a diiferent thing.You can use the UIWebView for this and then load the webview with the url.I think that would be the simple thing like this
views=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
[views setBackgroundColor:[UIColor lightGrayColor]];
NSString* urlStr = [NSString stringWithFormat: #"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", s_lat, s_long, d_lat, d_long];
NSURL *url=[NSURL URLWithString:urlStr];
NSURLRequest *req=[NSURLRequest requestWithURL:url];
//[views loadHTMLString:googlePage baseURL:requestURL];
[views loadRequest:req];
self.view=views;
And if you even don't want to use this then then you can use the MapKit provided in your XCode Frameworks.Hope this would help you.