How to draw routes in maps , ios6? - objective-c

I have been drawing routes in iOS5, but as the app has to be upgraded to iOS6, it does not allow to draw routes between coordinate locations . I have searched a lot, but ended up in vain. Can anyone help me on which api to use in iOS6 since google maps doesnt support anymore ???
EDIT : I have used Google iOS SDK previously to plot the routes which will auto take care of the polylines. As far as I have searched, i will be able to redirect to browser to show routes and navigation. But i need to draw this in-app [ iOS6 ]. Does iOS6 automatically does the routing, if so can u pls share some code to get a gist of it. This code sample I used it in iOS5 using google maps
// over lay map to draw route
routeOverlayView = [[UICRouteOverlayMapView alloc] initWithMapView:routeMapView];
diretions = [UICGDirections sharedDirections];
UICGDirectionsOptions *options = [[UICGDirectionsOptions alloc] init];
//setting travel mode to driving
options.travelMode = UICGTravelModeDriving;
[diretions loadWithStartPoint:startPoint endPoint:endPoint options:options];
// Overlay polylines
UICGPolyline *polyline = [directions polyline];
NSArray *routePoints = [polyline routePoints];
NSLog(#"routePoints %#",routePoints);
[routeOverlayView setRoutes:routePoints];

I did route in my application. I used The Google Geocoding API (used for iOS 6 only) https://developers.google.com/maps/documentation/geocoding/
Something like this:
- (void) sendRequestForLat: (CGFloat) lat lon: (CGFloat) lon
{
NSString* request;
NSInteger zoom = 12;
NSString* location = [NSString stringWithFormat: #"%f,%f", lat, lon];
NSString* daddr = [NSString stringWithFormat: #"%f,%f", myLat, myLon];
request = [NSString stringWithFormat: #"saddr=%#&daddr=%#&zoom=%i&directionsmode=walking", location, daddr, zoom];
NSString* typeMapsApp = isGoogleMapsAppPresent ? #"comgoogle" : #"";
NSString* urlString = [NSString stringWithFormat: #"%#maps://?%#", typeMapsApp, request];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: urlString]];
}

You're using a third party piece of code to do your route drawing, rather than using MapKit itself. The library you're using (which I found on GitHub here) hasn't been updated for two years.
I'd recommend you move away from that library to something more current. If you want you could consider using Google's iOS Map SDK, which supports iOS 6 (link here). You could combine this with Google's Directions API to draw polylines directly onto the map. Or you could stick with MKMapView, and again draw directly onto the map with polylines.
It's not that iOS has changed how it draws polylines onto a map - it's that the third-party code you're using is out of date.

Related

How to draw a walking route by two points Xcode

How would draw a walking route by two point (start and end).
I wont use polyline.
Please check following tutorial Draw Route Between two points Also Check BreadCrumb example of Apple hope its helps to you!
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&dirflg=w", start.latitude, start.longitude, end.latitude, end.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURLString]];
}

How to share picture on Google+?

Our two teams are developing same app: adroid team and iOS team. Android team was able to do text + photo sharing. Simple post with text is done normally but text + image requires google+ app and the code that opens small center'ed web view looks like this:
Intent shareIntent = ShareCompat.IntentBuilder.from(act)
.setText(message).setStream(uri).setType("image/jpeg")
.getIntent().setPackage("com.google.android.apps.plus");
act.startActivityForResult(shareIntent, SocialNetworksConstants.GOOGLE_POST_REQUERST);
However, I can't find anything similar in the newest Google+ iOS sdk. GPPShareBuilder protocol only has:
- (id<GPPShareBuilder>)setPrefillText:(NSString *)prefillText;
and
- (id<GPPShareBuilder>)setTitle:(NSString *)title
description:(NSString *)description
thumbnailURL:(NSURL *)thumbnailURL;
Has anybody faced this problem?
UPDATE: Here's a link to solution for Android. It looks like Android has some "ShareCompat" Android native library that extends functionality for sharing data between apps.
UPDATE2 Tried to use "setTitle:description:thumbnailURL:" with google+ sharing sample code in recent Google+ sdk. Tried to push NSURL of some image from bundle:
- (IBAction)shareButton:(id)sender{
...
if (title && description) {
//NSURL *imageUrl = [NSURL URLWithString:[deepLinkThumbnailURL_ text]];
NSString *imagePathString = [[NSBundle mainBundle] pathForResource:#"my_image" ofType:#"png"];
NSURL *imageUrl = [[NSURL alloc] initWithString:imagePathString];
shareBuilder = [shareBuilder setTitle:title
description:description
thumbnailURL:imageUrl]; // throw image path
}
However that didn't work out. Image placeholder is empty when google+ opens sharing window in safari. Only some external URL link is working.
Use this :
NSData *imageData = UIImagePNGRepresentation(myImage.image);
[(id< GPPNativeShareBuilder >)shareBuilder attachImageData:imageData];

How to specify the app name user was using to post - (via app name) using SDK 3.1

Using the new Facebook SDK 3.1 and iOS 6 there are 2 (actually 3) ways to post.
(Seems the new trend is to have more options to make it more simple??) OMG!!
Here is one:
SLComposeViewController *fbPost = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbPost addURL:[NSURL URLWithString:href]];
[self presentViewController:fbPost animated:YES completion:nil];
And this is another way using native dialogs:
[FBNativeDialogs presentShareDialogModallyFrom:self
initialText: nil
image: nil
url: [NSURL URLWithString:href]
handler:^(FBNativeDialogResult result, NSError *error) {
if (error) {
}
else
{
switch (result) {
case FBNativeDialogResultSucceeded:
break;
case FBNativeDialogResultCancelled:
break;
case FBNativeDialogResultError:
break;
}
}
}];
We, developers, think this is cool because we give a nice functionality to the user and also because our app name appears in the post and that can make some promotion of the app.
The funny thing is that latest implementations are not allowing to specify the app name was posting, the name appears after 'via'.
I tried aswell using SLRequest:
ACAccountStore *store = [[ACAccountStore alloc] init];
ACAccountType *fbType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSMutableDictionary *options = [[NSMutableDictionary alloc] init];
(options)[#"ACFacebookAppIdKey"] = kFacebookAppID;
(options)[#"ACFacebookPermissionsKey"] = #[#"publish_stream"];
(options)[#"ACFacebookAudienceKey"] = ACFacebookAudienceFriends;
[store requestAccessToAccountsWithType:fbType options:options completion:^(BOOL granted, NSError *error) {
if(granted) {
// Get the list of Twitter accounts.
NSArray *fbAccounts = [store accountsWithAccountType:fbType];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
(params)[#"link"] = href;
// (params)[#"picture"] = picture;
// (params)[#"name"] = name;
(params)[#"actions"] = #"{\"name\": \"Go Gabi\", \"link\": \"http://www.gogogabi.com\"}";
//Set twitter API call
SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST
URL:[NSURL URLWithString:#"https://www.facebook.com/dialog/feed"] parameters:params];
//Set account
[postRequest setAccount: [fbAccounts lastObject]];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if(error)
{
NSLog(#"%#", error.description);
}
else
{
NSLog(#"%#", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
}
}];
} else {
}
}];
Unfortunatelly to share that name is not so trivial anymore, I wonder why and who was designing the new implementation...
I would appreciate to get some help on that, thanks in advance.
I try to make my questions funny because is soo boring spend time in so trivial topics...
When you use the SLComposeViewController, it's actually the system presenting to you their controller, and it's the user who sends using the post button. Therefore on Facebook it appears as "via iOS".
There's no way to change that.
Using the Facebook SDK 3.1, under the hood it is also using the iOS 6 native integration, so when you're calling the FBNativeDialogs, on iOS 6, it's using SLComposeViewController.
Facebook continued to develop their SDK because they provide a couple of nice modules to use "out of the box" - this includes friends list selector etc... But I believe the biggest reason for Facebook to continue supporting their SDK it for backward compatibility. Under the hood if you're not on iOS 6, it falls back to it's library, and if you are on iOS 6, it uses the system integration.
Facebook is a big thing, and now it's natively available a lot of developers will be using it, just like Twitter's integration last year. The problem of course is at that point the developer has the option to drop older iOS support, or... have a lot of duplicate code, in the sense that they will check for SLComposeViewController and if it's not available (iOS 5) then use the old Facebook SDK... You can imagine how this would become very messy very quickly.
So, the Facebook SDK (3.1) is using iOS system Facebook integration if available, or if not, it's own. In a nutshell, unless you really want the Facebook SDK goodies (friend picket to name one), and you're not planning on supporting iOS < 6 then you don't need to worry about their SDK, just use the Social framework.
So, back to your question, there are 3 ways to post to Facebook ? Actually taking into consideration what I mentioned, there are 2 ways in iOS 6: SLComposeViewController or, SLRequest. On older iOS versions, only 1: Facebook SDK.
Since the SLComposeViewController is owned by the system, not your app, it will always share as "via iOS".
On the other hand SLRequest will show your apps name. When you specify an account for your SLRequest, that account was acquired via the ACAccountStore as a result of passing in some options including ACFacebookAppIdKey, which will be used to determine your Facebook apps name to post onto the users feed as part of the post.
Hope this helps.

Preview image of map

How can I make a preview icon like in the iPhone Map application?
Screenshot http://img835.imageshack.us/img835/1619/img0016x.png
Is there a function for this?
In iOS 7 use MKMap​Snapshotter. From NSHipster:
MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
options.region = self.mapView.region;
options.size = self.mapView.frame.size;
options.scale = [[UIScreen mainScreen] scale];
NSURL *fileURL = [NSURL fileURLWithPath:#"path/to/snapshot.png"];
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
[snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
if (error) {
NSLog(#"[Error] %#", error);
return;
}
UIImage *image = snapshot.image;
NSData *data = UIImagePNGRepresentation(image);
[data writeToURL:fileURL atomically:YES];
}];
Before iOS7 do one of the following:
Add a live map and disable interaction.
Use the Google Static Maps API (explained below).
Create a MKMapView and render it to an image. I tried this (see previous edit) but couldn't get the tiles to load. I tried calling needsLayout and other methods but didn't work.
Apple's deal with Google is more reliable than a free API, but on the bright side, it is really simple. Documentation is at http://code.google.com/apis/maps/documentation/staticmaps/
This is the minimum amount of parameters for practical use:
http://maps.googleapis.com/maps/api/staticmap?center=40.416878,-3.703530&zoom=15&size=290x179&sensor=false
A summary of the parameters:
center: this can be an address, or a latitude,longitude pair with up to 6 decimals (more than 6 are ignored).
format: png8 (default), png24, git, jpg, jpg-baseline.
language: Use any language. Default will be used if requested wasn't available.
maptype: One of the following: roadmap, satellite, hybrid, terrain.
scale: 1,2,4. Use 2 to return twice the amount of pixels on retina displays. 4 is restricted to premium customers.
Non paid resolution limits are 640x640 for 1 and 2.
sensor: true or false. Mandatory. It indicates if the user is being located using a device.
size: size in pixels.
zoom: 0 (whole planet) to 21.
There is a few more to add polygons, custom markers, and style the map.
NSData* data = [NSData dataWithContentsOfURL:#"http://maps.googleap..."];
UIImage *img = [UIImage imageWithData:data];
You can use Google Maps Static API to generate an image instead of loading an entire UIMapView.

Get list of installed apps on iPhone

Is there a way (some API) to get the list of installed apps on an iPhone device.
While searching for similar questions, I found some thing related to url registration, but I think there must be some API to do this, as I don't want to do any thing with the app, I just want the list.
No, apps are sandboxed and Apple-accepted APIs do not include anything that would let you do that.
You can, however, test whether a certain app is installed:
if the app is known to handle URLs of a certain type
by using [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"thisapp://foo"]
You can get a list of apps and URL schemes from here.
For jailbroken devices you can use next snipped of code:
-(void)appInstalledList
{
static NSString* const path = #"/private/var/mobile/Library/Caches/com.apple.mobile.installation.plist";
NSDictionary *cacheDict = nil;
BOOL isDir = NO;
if ([[NSFileManager defaultManager] fileExistsAtPath: path isDirectory: &isDir] && !isDir)
{
cacheDict = [NSDictionary dictionaryWithContentsOfFile: path];
NSDictionary *system = [cacheDict objectForKey: #"System"]; // First check all system (jailbroken) apps
for (NSString *key in system)
{
NSLog(#"%#",key);
}
NSDictionary *user = [cacheDict objectForKey: #"User"]; // Then all the user (App Store /var/mobile/Applications) apps
for (NSString *key in user)
{
NSLog(#"%#",key);
}
return;
}
NSLog(#"can not find installed app plist");
}
for non jailbroken device, we can use third party framework which is called "ihaspp", also its free and apple accepted. Also they given good documentation how to integrate and how to use. May be this would be helpful to you. Good luck!!
https://github.com/danielamitay/iHasApp
You could do this by using the following:
Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
SEL selector = NSSelectorFromString(#"defaultWorkspace");
NSObject* workspace = [LSApplicationWorkspace_class performSelector:selector];
SEL selectorALL = NSSelectorFromString(#"allApplications");
NSMutableArray *Allapps = [workspace performSelector:selectorALL];
NSLog(#"apps: %#", Allapps);
And then by accessing each element and splitting it you can get your app name, and even the Bundle Identifier, too.
Well, not sure if this was available back when the last answer was given or not (Prior to iOS 6)
Also this one is time intensive, yet simple:
Go into settings > Gen. >usage. The first category under usage at least right now is Storage.
It will show a partial list of apps. At the bottom of this partial list is a button that says "show all apps".
Tap that and you'll have to go through screen by screen, and take screenshots (Quick lock button and home button takes a screenshot).
I'm doing this now and I have hundreds of apps on my iPhone. So it's going to take me a while. But at least at the end of the process I'll have Images of all my apps.