I am using Apple Map's in my app and on my view i want to show the driving direction from the user location to the current location that i have on the view, now i just want all this inside my app only i.e i can show the driving direction's on the mapview, I have tried using the apple map application but after i make call to it from my application it takes me to apple's map application where i get the driving direction's but i can not return back into my application so i am thinking that i can do something in my application itself so that i can get the driving directions on my current view itself ..
NSString* addr = [NSString stringWithFormat:#"http://maps.apple.com/maps?daddr=%1.6f,%1.6f&saddr=%1.6f,%1.6f",coordinate.latitude,coordinate.longitude,mapView.userLocation.coordinate.latitude,mapView.userLocation.coordinate.longitude];
NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
this code takes me to the apple's map app from my native app but i can't return directly back to my app.is there a possible solution so that i can move back to my APP AFTER GETTING THE DRIVING DIRECTIONS ?? (webview didnot work for me.can i add a back button on apple's app or what ).Please help.... Thanks a lot !!
Or Please can any one suggest me a better code for implementing so that i can do all of that in my application only ?
I want an in-app map depicting the navigation routes and driving directions...
This is not the way to achieve the directions,
I have made a sample for you which covers all the iOS versions, New Google Maps and the iOS 6 tom tom maps as well.
Here it is:
if([[[UIDevice currentDevice] systemVersion] compare:#"6.0" options:NSNumericSearch] == NSOrderedDescending){
//6.0 or above
NSString *Destinationlatlong =[NSString stringWithFormat:#"%#,%#",your.latitude,your.longitude];
NSString* addr = [NSString stringWithFormat:#"comgooglemaps://?saddr=%f,%f&daddr=%#",[AppDelegate zDelegate].location.coordinate.latitude,[AppDelegate zDelegate].location.coordinate.longitude, Destinationlatlong];
addr=[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL* url = [[[NSURL alloc] initWithString:addr]autorelease];
// NSLog(#"url %#",url);
if ([[UIApplication sharedApplication]canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}else{
CLLocationCoordinate2D coords =
CLLocationCoordinate2DMake([your.latitude doubleValue],[your.longitude doubleValue]);
MKPlacemark *placeMark = [[MKPlacemark alloc]
initWithCoordinate:coords addressDictionary:nil];
MKMapItem *destination = [[MKMapItem alloc]initWithPlacemark:placeMark];
[destination openInMapsWithLaunchOptions:nil];
}
}else{
NSString *Destinationlatlong =[NSString stringWithFormat:#"%#,%#",your.latitude,your.longitude];
NSString* addr = [NSString stringWithFormat:#"http://maps.google.com/maps?saddr=Current+Location&daddr=%#",Destinationlatlong];
addr=[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL* url = [[[NSURL alloc] initWithString:addr]autorelease];
// NSLog(#"url %#",url);
if ([[UIApplication sharedApplication]canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}else{
UIAlertView *alert=[[[UIAlertView alloc] initWithTitle:#"Warning!" message:#"Device does not support this functionality" delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles: nil]autorelease] ;
[alert show];
}
}
This should get you started. In short, get driving instruction from google api in json, parse it, and display it on your own map using MKPolyline
http://iosguy.com/2012/05/22/tracing-routes-with-mapkit/
Related
Want to share video using UIActivityViewController with its thumbnail and playbutton icon.
I used .mp4 url but facebook shows url not thumbnail.
how to make possible to show video(thumbnail with play button) on Facebook without using following code, because it doesnt work.
ALAsset * asset = [[ALAsset alloc] init];
[asset setVideoAtPath:urlToVideoFile completionBlock:NULL];
NSArray * activityItems = #[asset];
UIActivityViewController * activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:NULL]
The code which you have put is adding asset into array, don't put asset directly instead put url and try.
I am trying to use FBPlacePickerViewController and it doesn't seem to load any data.
Here is my code:
FBPlacePickerViewController *picker = (FBPlacePickerViewController*)segue.destinationViewController;
picker.navigationController.navigationBarHidden = YES;
picker.delegate = self;
picker.radiusInMeters = 1000;
picker.resultsLimit = 30;
if([TonerAppDelegate instance].lastLocation != nil){
picker.locationCoordinate = [TonerAppDelegate instance].lastLocation.coordinate;
[picker loadData];
}
[TonerAppDelegate instance].lastLocationUpdateFunction = ^{
picker.locationCoordinate = [TonerAppDelegate instance].lastLocation.coordinate;
[picker loadData];
};
It is an embed segue (iOS 6). I verify that the picker is a valid object. The [picker loadData] method does get called, and the coordinate data is perfectly valid. I am not getting any exceptions or warnings. I've allowed my app to access to my location in iOS and I double-verified that in Settings. My iPod is connected to the Internet and the connection works perfectly. All the other apps can use location services without any problem. So, there probably is a problem with my implementation of the place picker. I've also implemented the -(void)placePickerViewControllerDataDidChange:(FBPlacePickerViewController *)placePicker and -(BOOL)placePickerViewController:(FBPlacePickerViewController *)placePicker shouldIncludePlace:(id<FBGraphPlace>) methods of the delegate, and they aren't getting called either. What am I doing wrong?
Thanks,
Can.
Found the answer: I wasn't creating the Facebook session before displaying the place picker. I totally forgot about the session. It'd be nice to see Facebook add an assertion check in loadData method of the picker for an existing Facebook session. I've created the session, and THEN tried my code, and it works perfectly now.
Im trying to create a image gallery using UICollectionView. But the dispatch_queue does not seem to download image instead it skips the download and continues executing the next statement.
Below is my code:
for(int i=0;i<[_urlArray count];i++){
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0), ^{
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"%#",[_urlArray objectAtIndex:i]]];
NSData *data = [NSData dataWithContentsOfURL:url];
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
path = [path stringByAppendingString:[NSString stringWithFormat:#"%d.png",i]];
NSLog(#"img data %#",data);
[data writeToFile:path atomically:YES];
UIImage *theImage=[UIImage imageNamed:path];
[_imgArray addObject:theImage];
dispatch_async(dispatch_get_main_queue(), ^{
});
});
}
I even tried AFNetworking and SDWebImage. But did not help me. Please help me with this. Thank you.
Have you tried to store all data and Images from URL to iOS Cache memory or any DB?
i am using googlemap sdk for ios 6 in my project
The problem i am facing is with Marker options
GMSMarkerOptions *londonOptions = [[GMSMarkerOptions alloc] init];
londonOptions.position = CLLocationCoordinate2DMake(51.500,-0.127);
londonOptions.title = nil;
londonOptions.snippet = nil;
[mapView_ addMarkerWithOptions:londonOptions];
Google states that if i set the title and snippet to nil then the marker would not show a callout if i tap on it.
but it does show an callout on tapping on it.
Has anyone faced this problem
Thanks in advance
Regards
Nitesh
I worked around it by returning an empty uiview :) but as share said, it is fixed now
In Restkit versions before v0.20.0 it used to be a simple enough to check for service unavailability and show appropriate responses.
objectManager.client.serviceUnavailableAlertEnabled = YES;
How can we achieve the same in latest RestKit?
Figured it out myself.
Since RKClient is no more in the latest RestKit it has been replaced by the AFHTTPClient from AFNetworking. The wrapper for reachability in AFNetworking is simple enough to use.
Firstly add the SystemConfiguration.framework to your project.
Then add #import <SystemConfiguration/SystemConfiguration.h> to your .pch file.
Finally register a callback block whenever the network reachability changes.
[objectManager.HTTPClient setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
if (status == AFNetworkReachabilityStatusNotReachable) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"No network connection"
message:#"You must be connected to the internet to use this app."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}];
This also works when the app is started when no internet connection is present.