Xcode google map navigation - iphone

I currently have an application which will drop pins onto various points of interest on a map, all done programmatically on the iPhone.
What I am aiming to get done now is to allow a user to navigate to that location and get turn by turn directions by calling up the built in navigation tools on the iPhone.
Is there anyway that I can do this? I've scoured the developer center and searched both google and here and couldn't find anything about this.

You're not allowed to use google directions within your app. The only way you can do this is to send them to the google maps application as per:
- (void)getDirections {
CLLocationCoordinate2D start = { (startLatitude), (startLongitude) };
CLLocationCoordinate2D end = { (endLatitude), (endLongitude) };
NSString *googleMapsURLString = [NSString stringWithFormat:#"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f", start.latitude, start.longitude, end.latitude, end.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURLString]];
}

Related

Opening an Native ios App inside an Another App?

i have this idiotic Question .
Is there any way open an another ios Application inside a view controller of a app.
I know we can open a another Ios app if we have url schema and the calling application goes to background and called application goes to background.
Is there any way ?? i just got a dream ,so am asking can we do it??
It is not possible to do it with the iPhone SDK. You can do this though by using Private APIs.
You can make it work on jailbroken devices.
But if you want to call native social apps like facebook or twitter you should use this code.
It works and apple approves it.
NSURL *fbNativeAppURL = [NSURL URLWithString:#"fb://"];
if ( [[UIApplication sharedApplication] canOpenURL:fbNativeAppURL])
{
[[UIApplication sharedApplication] openURL:fbNativeAppURL];
}
or
NSURL *twNativeAppURL = [NSURL URLWithString:#"twitter://"];
if ( [[UIApplication sharedApplication] canOpenURL:twNativeAppURL])
{
[[UIApplication sharedApplication] openURL:twNativeAppURL];
}

Google map Implementation in 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.

iOS: Connect to Facebook without leaving the app for authorization

I know that it was possible before the Graph API.
I work on an iPhone app that may not be in the background (one of the requirements).
In addition there is a login screen on the app launching.
Therefore it is not suitable to go to background in order to authenticate to Facebook and then return to the app and login once again each time the user wants to share something.
So, my question is if there is a way to authenticate with Facebook without leaving the app.
BTW, I have tried to use the old API.
It worked in the beginning but yesterday it stopped working.
I just see a blank screen inside the old Facebook login web view.
I have also checked one of my old apps that use that old Facebook Connect API and I get the same blank login screen in that app too.
Any idea will be appreciated.
Thank you in advance.
--
Michael.
In Facebook.m
- (void)authorizeWithFBAppAuth:(BOOL)tryFBAppAuth
safariAuth:(BOOL)trySafariAuth {
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
_appId, #"client_id",
#"user_agent", #"type",
kRedirectURL, #"redirect_uri",
#"touch", #"display",
kSDKVersion, #"sdk",
nil];
method comment out this
UIDevice *device = [UIDevice currentDevice];
if ([device respondsToSelector:#selector(isMultitaskingSupported)] && [device isMultitaskingSupported]) {
if (tryFBAppAuth) {
NSString *fbAppUrl = [FBRequest serializeURL:kFBAppAuthURL params:params];
didOpenOtherApp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:fbAppUrl]];
}
if (trySafariAuth && !didOpenOtherApp) {
NSString *nextUrl = [NSString stringWithFormat:#"fb%#://authorize", _appId];
[params setValue:nextUrl forKey:#"redirect_uri"];
NSString *fbAppUrl = [FBRequest serializeURL:loginDialogURL params:params];
didOpenOtherApp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:fbAppUrl]];
}
}
This will prevent the app from going to background and show you the standard fb dialog.
Here you have an alternative solution.
If you don't like to change the facebook sdk code and want a solution that allows you to choose between SSO or the old-fashioned mechanism, you can Implement an extension like this:
//Facebook_SSOExtension.h
--------------------------------------------------------
#interface Facebook(SSOExtension)
-(void) authorize:(NSArray*)permissions useSSO:(BOOL) useSSO;
#end
//Facebook_SSOExtension.m
--------------------------------------------------------
//So warnings do not appear
#interface Facebook(PrivateSSOExtension)
- (void)authorizeWithFBAppAuth:(BOOL)tryFBAppAuth
safariAuth:(BOOL)trySafariAuth;
-(void) setPermissions:(NSArray*) permissions;
#end
#implementation Facebook(SSOExtension)
-(void) authorize:(NSArray*)permissions useSSO:(BOOL) useSSO
{
[self setPermissions: permissions];
[self authorizeWithFBAppAuth:useSSO safariAuth:useSSO];
}
#end
Even though this requires more work than commenting-out the sso code, you will be able to update the facebook-sdk without major problems (if they rename authorizeWithFBAppAuth:safariAuth: your extension will not work, use asserts to detect this issue quickly). Also, if you are building a reusable component to interact with facebook without repeating things over and over again, this will save you some work too.
Cheers.

How to get a map view in an iPhone app

How can I get this kind of map view in my application?
Any examples?
You'll need to use an MKMapView. For the popup, you'll need an annotation. Looking at the MKMapView documentation should get you pretty far..
You should be using MKMapView - as donkim mentioned do some reading on MKMapView, taht would get you pretty far. You can use MKAnnotations for the maps annotations. You can google for "custom annotations" if you want to want to use custom images for annotations.
You can refer to this post that i posted a while ago for a memory leak, but it pretty much has the code to show annotations on the map. I have borrowed the code from internet too...
I guess I need to call this... in
//NSString *latlong = [[NSString stringWithFormat:#"%f, %f", 52.366428f,4.896349f] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//........for destination location.
//NSString *dlatlong = [[NSString stringWithFormat:#"%f, %f", coordinate.latitude, coordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//for the current location. this. where coordinate is CLLocationManager2D.
//NSString *url = [NSString stringWithFormat: #"http://maps.google.com/maps?ll=%#&saddr=%#&daddr=%#",
//latlong, latlong, dlatlong];
need not to use mkmapkit.
There is a easier way of show a location on the map, however this approach will not implement a map view inside your application but it will open the map application.
[[UIApplication sharedApplication] openUrl:#"http://maps.google.com/maps?q=Oslo"];
After the q- parameter key you can write the same string as you normally write in google maps specifying the address. Read the documentation for UIApplication class for more information on this. Note, this will also automatically make a annotation for the location.
Just mention this because others may find this a useful if they don't need the map inside the application.
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html
Here is a list of other parameters:
http://mapki.com/wiki/Google_Map_Parameters

Using Current Location from Location Manager in a Google Maps openURL?

Been looking into this for a while today however I can't seem to get my head around how to get the users current location into a Google Maps URL to open the Google Maps app with directions populated.
I've taken this code from another tutorial and added it into my app. I need to get the "start" lat/lng from the below into my IBAction to open the Google Maps app.
- (void)locationUpdate:(CLLocation *)location {
// Lat/Lng of user (Needs to be sent to IBAction for btnDirections)
CLLocationCoordinate2D start = { location.coordinate.latitude, location.coordinate.longitude };
}
The below is my IBAction for my "Get Directions" button.
- (IBAction) onButtonClick:(id) sender {
if(sender == btnDirections) {
CLLocationCoordinate2D destination = { 52.48306771095311, -1.8935537338256836 };
NSString *googleMapsURLString = [NSString stringWithFormat:#"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f",
newLocation.coordinate.latitude, newLocation.coordinate.longitude, destination.latitude, destination.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURLString]];
}
}
I have done this previously in another app, however that view included a map showing the user location which allowed me to get the lat/lng easily.
Thanks in advance.
Simply pass "Current+Location" as a parameter to the google maps application:
http://maps.google.com/maps?saddr=Current+Location&daddr=Heathrow+Airport+London
In my code, I have an URL of the format :
http://maps.google.com/maps?daddr=%f,%f&saddr=%f,%f
(So that's 'maps' added from yours).
Other than that, you can setup your location request to stop after a set precision, did you setup precise enough for your purpose?
Oh, last note, getting current location might not work in simulator.
You need to make the user's current location available to the onButtonClick: method. You are creating the start structure on each location update, but you are never making it available outside of that method.