I successfully open Iphone default app with current user location but if user has selected a different language (e.g.. for Dutch Current Location = Aktueller Ort) then current location and route is totally wrong.
NSString *mystr=[[NSString alloc] initWithFormat:#"http://maps.google.com/maps?saddr=Current+Location&daddr=Destination"];
NSURL *myurl=[[NSURL alloc] initWithString:mystr];
[[UIApplication sharedApplication] openURL:myurl];
Although we can detect current language and match using switch case but we need to translate "Current Location" to all supported languages by iphone map app.
I tried wiki link for parameters and found hl parameter but not worked for me I think method for apply parameter by me is wrong or something.
So how can I open map app with particular fix language like english even when user selected different language?
thanx for any help!
You can get the current user location by the Core Location Framework and pass latitude and longitude to the google maps url. Or you can check the current language and translate "Current Location" in a lot of lang and pass it to the url.
NSString *language = [[NSLocale preferredLanguages] objectAtIndex:0];
Related
Now, in standard behavior of localization, the iOS determines the currently set Language of iPhone and uses the Localizable.strings file to set the appropriate text.
My client, however, requires a multi-language iOS application in which the language is set within the application independent of the native iOS preferred language. i.e. the application may have different language to what the iOS is currently set to on the iPhone.
Anybody with any ideas about how to go about implementing this scenario?
My idea:
I could create a custom static class similar to the NSLocalizeString and hard code strings within that and return appropriate language string w.r.t language set within the app, and if that is a possible solution then any suggestions about how to structure that class)
You could:
store your translation string in a .plist file (string_key/translation) for each language;
read the appropriate plist (depending on the language currently set) in a NSDictionary;
access the dictionary for each string you want to display (just like you would do with NSLocalizeString).
I once had to create a flashchards app and the client needed to change the language at will. I don't have the source code for it at my box right now, but I remember using this tutorial. Also check the sample code they use.
Side note - dissing your clients publicly is really unprofessional.
Create plist files with needed language. I use {LANG}_{CLASS NAME} and {CLASS NAME} for default with all localized strings.
After that I made a method that checks if proper file exists, take it or default if missing and returns an NSDictionary object depending on the device language, called on class init. This idea can also be used, if you implement localized nibs by adding nib name to the strings file.
+ (NSDictionary *) getLocalized: (NSString *) contollerName andLang:(NSString *) lang {
NSString *fullPath = nil;
// You can use device lang if needed
NSString * curLang=[[NSLocale preferredLanguages] objectAtIndex:0];
fullPath = [[NSBundle mainBundle] pathForResource: [NSString stringWithFormat:#"%#_%#",contollerName,lang] ofType: #"plist"];
if (!fullPath) {
fullPath = [[NSBundle mainBundle] pathForResource:contollerName ofType:#"plist"];
}
return [NSDictionary dictionaryWithContentsOfFile:fullPath];
}
So, it can be called by something like that:
[tools getLocalized:[Controller.class description] andLang:#"XX"];
You can use standard localization (.strings files and localized .xibs) and force your app to use a language other than the iOS language setting. For details on how to achieve this, see this post: Change language of the ios application
Note that if you (or rather your client!) want to switch language on the fly while using the app, it will be more complicated--you would need to implement some sort of refresh feature and make sure the xibs are reloaded.
I would like to have a link in a web page in such a way that when the link is clicked it opens the standard "Maps" view in iPhone.
If such a thing is possible, what tag format do I need to use with the link?
It's pretty simple; you don't even need to use a specific scheme identifier. Any Google Maps URL will be opened with the Maps app automatically, as long as all the parameters are supported.
So links like these:
http://maps.google.com/maps?q=cupertino
http://maps.google.com/maps?daddr=San+Francisco,+CA&saddr=cupertino
Would automatically be opened in Maps. To find out more about what works and what doesn't see the Map Links page from the Apple URL Scheme Reference.
I used this code which works passing longitude lattitude:
NSString *url = [NSString stringWithFormat: #"http://maps.google.com/maps?saddr=%f,%f&daddr=%#",cur_lat, cur_lon,[loc stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(#"current %f %f",cur_lat,cur_lon);
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:url]];
When a user whose location services are off, goes to a page that needs Location, a UIAlertView would appear, and at the bottom, there is a button named "Setting". When "setting" is clicked, it would jump to System Setting - Location Service.
What's the button action, or the URI for navigating to Location Services?
iOS doesn't provide an explicit way or URL to navigate to the Settings page.
As far as Location services are concerned, whenever an app tries to use location services, if the "Location Services" in the settings page is set to NO, iOS prompts an alertView for the user to enable (set YES) the option. On subsequent launches, if this option is set to YES, the user will not get this alertView.
All you need to do is to modify your Info.plist file to include location-services in your UIRequiredDeviceCapabilities entry
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=LOCATION_SERVICES"]];
You can do the above, but I don't know whether the App will pass through Apple's app review.If you know, please tell me.
Reference: jump to setting interface in iOS.
This will lead you to app setting page..Were you can change the Setting for you application including Location service..
NSURL *appSettings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:appSettings];
I am opening Maps app to show directions from user's Current Location to a destination coordinate, from my code. I am using the following code to open the Maps app. I am calling this code when a button is pressed. getCurrentLocation is a method that returns the recently updated location.
- (void)showDirectionsToHere {
CLLocationCoordinate2D currentLocation = [self getCurrentLocation]; // LINE 1
NSString* url = [NSString stringWithFormat: #"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f",
currentLocation.latitude,
currentLocation.longitude,
destCoordinate.latitude,
destCoordinate.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}
Here [self getCurrentLocation] in LINE 1 uses CLLocationManager to determine the Current Location and returns the value.
Note: I have not yet implemented the code in LINE1. I've just planned to do it that way.
My questions are:
Is this good practice to calculate the Current Location, at the time the Maps app is called?
Will [self getCurrentLocation] return the Current Location before openURL gets called?
Do I have to determine the Current Location well before opening the Maps app?
I am little bit confused about these things. Kindly guide me. Thanks.
You don't have to determine the user's current location yourself, the Maps app will take care of it.
Instead of passing a latitude/longitude pair you can pass Current%%20Location and Maps will determine the user's current location itself.
%20 is a url-encoded space character, and the extra % escapes the actual % so it won't be interpreted as a format substitution.
Thanks to #Carlos P for pointing out my escape character blunder in the original answer.
Using "Current Location" as saddr only works if the user has the system language set to English. The best options is really to get the current position from Core Location and use that as saddr.
As pazustep pointed out, "Current Location" works only for English. In Italian, for example, the correct string is "Posizione attuale".
Sniffing in the iPhone firmware I detected all the "Current Location" translations and I wrote a class that provides the correct string needed for any (currently) supported language.
There's a post about this (source code included) on my blog: http://www.martip.net/blog/localized-current-location-string-for-iphone-apps.
You can use the new MKMapItem class for iOS 6. See the Apple API docs here
Basically, you will use something like this, if routing to destination coordinates (destCoordinate):
MKPlacemark* place = [[MKPlacemark alloc] initWithCoordinate: destCoordinate addressDictionary: nil];
MKMapItem* destination = [[MKMapItem alloc] initWithPlacemark: place];
destination.name = #"Name Here!";
NSArray* items = [[NSArray alloc] initWithObjects: destination, nil];
NSDictionary* options = [[NSDictionary alloc] initWithObjectsAndKeys:
MKLaunchOptionsDirectionsModeDriving,
MKLaunchOptionsDirectionsModeKey, nil];
[MKMapItem openMapsWithItems: items launchOptions: options];
In order to support both iOS 6+ and pre iOS 6 in the same code, I'd recommend using something like this code that Apple has on the MKMapItem API doc page:
Class itemClass = [MKMapItem class];
if (itemClass && [itemClass respondsToSelector:#selector(openMapsWithItems:launchOptions:)]) {
// iOS 6 MKMapItem available
} else {
// use pre iOS 6 technique
}
This would assume that your Xcode Base SDK is iOS 6 (or Latest iOS).
In this other answer, I offer a robust technique for iOS 5.1 and lower
Having follow the tutorial at http://mithin.in/2009/06/22/using-iphone-sdk-mapkit-framework-a-tutorial/ to integrate the MapKit into my application. However, I want to be able to display an annotation for a dynamic "incident" on the map. Here's where I'm having problems.
Basically my apps an RSS reader, and it downloads everything and saves each item of the feed (as in Story 1, Story 2) as currentItem. The data I want to grab and use to map the annotation can be found under currentItem.title - but I can't seem to get it to work in this tutorial's code or find the right place to put it.
The RSS feed I'm using doesn't have any latitude/longitude information either - making it even harder.
Any help would be great - I've been working on this for a couple of days now with still no luck.
UPDATE: I'm even considering launching the Google Maps application instead showing the annotation. But this in itself is raising issues. Below is the code I'm using but its throwing errors everywhere.
NSString *title = currentItem.title;
int zoom = 13;
NSString *stringURL = [NSString stringWithFormat:#"http://maps.google.com/maps?q=%##%1.6f,%1.6f&z=%d", title, zoom];
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
In the end I just mapped the title using reverse lookup, and added the country afterwards so results would only be in the country where the address is. Not ideal, but it seems to work OK.