iOS open link with maps apps - html

I'm working on an event app and I'm trying to add a "Get directions" button that opens up directions in either Apple Maps or Google Maps. I'm happy to use Apple maps for now because it's easy to embed with http://maps.apple.com/?q=XYZ().
My app is displaying an HTML website with a UIWebView, so this may be the problem, but when you press the link it actually opens within the UIWebView and displays Google Maps randomly but accurately. Is there a function I can put into my HTML code that forces the link to open in the native Apple or Google Maps?

COMPLETE ANSWER
CODE:
- (IBAction)getDirectionsAction:(id)sender {
NSURL *googleURL = [[NSURL alloc]
initWithString:[NSString stringWithFormat:#"comgooglemaps://?daddr=%#", #"44.294349,-70.326973"]];
NSURL *googleWebURL =
[[NSURL alloc] initWithString:[NSString stringWithFormat:#"http://www.maps.google.com/maps?daddr=%#",
#"44.294349,-70.326973"]];
NSURL *appleURL = [NSURL URLWithString:#"http://maps.apple.com/?daddr=311+East+Buckfield+Road+Buckfield+Maine"];
NSURL *wazeURL = [NSURL URLWithString:#"waze://?ll=44.294349,-70.326973&navigate=yes"];
// Lets try the Waze app first, cuz we like that one the most
if ([[UIApplication sharedApplication] canOpenURL:wazeURL]) {
[[UIApplication sharedApplication] openURL:wazeURL
options:#{}
completionHandler:^(BOOL success){
}];
return;
}
// Lets try the Apple Maps app second
if ([[UIApplication sharedApplication] canOpenURL:appleURL]) {
[[UIApplication sharedApplication] openURL:appleURL
options:#{}
completionHandler:^(BOOL success){
}];
return;
}
// If Apple Maps is unsuccessful, let's try the Google Maps app
if ([[UIApplication sharedApplication] canOpenURL:googleURL]) {
[[UIApplication sharedApplication] openURL:googleURL
options:#{}
completionHandler:^(BOOL success){
}];
return;
}
// Uh, oh...Well, then lets launch it from the web then.
else {
[[UIApplication sharedApplication] openURL:googleWebURL
options:#{}
completionHandler:^(BOOL success){
}];
}
}
PLIST PROPERTIES:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>http://maps.apple.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>http://maps.google.com/</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
</dict>
</dict>
</dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>waze</string>
<string>comgooglemaps</string>
</array>
<key>NSLocationAlwaysUsageDescription</key>
<string>For Use for directions</string>
BUTTON
1X
2X
3X

Instead of using the http protocol in your URL, try using the maps protocol instead, so that your link looks something like:
maps://maps.apple.com/?q=Test+Search
You can also open it in Google Maps, if the user has it installed, by using a URL such as:
comgooglemaps://?q=Test+Search
Though you might get unexpected results if the user doesn't have it installed.
If this doesn't work, it's possible to use the UIWebView delegate method webView:shouldStartLoadWithRequest:navigationType: to intercept links and open the Maps application properly.

Here you can find info on the Google Maps URL Scheme
UIApplication.sharedApplication().openURL(NSURL(string:
"comgooglemaps://?q=XYZ")!)
Will enforce Google Maps to be used.
You might want to do
UIApplication.sharedApplication().canOpenURL(NSURL(string:"comgooglemaps://")!)
first, to ensure that Google Maps is available. If not, simply call your regular
http://maps.apple.com/?q=XYZ()
to open apple maps.

Related

Adobe Air Can't Connect to Server on iOS10

I have an application on Appstore like 2 years.
I developed with Adobe AIR.
On iOS10 my app not working. Can't connect to http links.
I debug and get error from connections:
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: http://api.website.net/check.php
I used HTTPStatusEvent.HTTP_STATUS for understand any solution, it gives 0
Any methods to solve?
MY CODE:
var urlReq:URLRequest = new URLRequest ("http://api.website.net/check.php");
urlReq.method = URLRequestMethod.POST;
var urlVars:URLVariables = new URLVariables();
urlVars.user_id = Main.instance.userID;
urlReq.data = urlVars;
var loader:URLLoader = new URLLoader (urlReq);
loader.addEventListener(Event.COMPLETE, onCreditComplete);
loader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, httpStatusHandler);
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(urlReq);
Sounds like it's related to the iOS App Transport security settings.
To enable http requests you will need to either define the domains as exceptions in your application descriptor:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>api.website.net</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
or add a global ignore security setting:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
These settings should be added to the InfoAdditions node in your iPhone settings of your application descriptor:
<iPhone>
<InfoAdditions><![CDATA[
<key>UIDeviceFamily</key>
<array>
<string>1</string>
<string>2</string>
</array>
<!-- Add the above settings here -->
]]></InfoAdditions>
<requestedDisplayResolution>high</requestedDisplayResolution>
<Entitlements>
<![CDATA[
]]>
</Entitlements>
</iPhone>

iOS share extension in chrome

Just added share extension to my app.
It's working fine in safari.
When launching it from Chrome the "ExtensionPreprocessingJS.js" isn't called.
as a result the following code is not invoked:
MyExtensionJavaScriptClass.prototype = {
run: function(arguments) {
// Pass the baseURI of the webpage to the extension.
arguments.completionFunction({"baseURI": document.baseURI});
},
Please advise.
That behavior is documented as being a Safari option, not something that applies to every web browser.
In Share extensions (on both platforms) and Action extensions (iOS only), you can give users access to web content by asking Safari to run a JavaScript file and return the results to the extension.
[Emphasis mine]
Try to put/replace/add this to your info.plist of extension
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsText</key>
<true/>
<key>NSExtensionActivationSupportsWebPageWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
</dict>
<key>NSExtensionJavaScriptPreprocessingFile</key>
<string>DemoPreprocessor</string>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>
No need for that complicated stuff. This works both in Google Chrome and Safari:
override func viewDidLoad() {
super.viewDidLoad()
for item in extensionContext!.inputItems {
if let attachments = item.attachments {
for itemProvider in attachments! {
itemProvider.loadItemForTypeIdentifier("public.url", options: nil, completionHandler: { (object, error) -> Void in
if object != nil {
println(object) //This is your URL
}
})
}
}
}
}

Why i cannot render my KML service in google maps?

I have been trying to render my KML service in the google maps by the following.
var ctaLayer = new google.maps.KmlLayer({
url: 'http://DomainName/GeoSystem/redrawKML'
});
ctaLayer.setMap(map);
But I am getting undefined as a result with ctaLayer object when i have checked the status.
But the same service is working good, If i have tried to parse the KML service with geoXML parser. Now, I am confused and having no idea . Why I can not render my KML Service with the google maps KML Layer in google maps.
Any help is much appreciated.
My Woring code with GeoXML library follows.
var geoXml = new geoXML3.parser({
map : map,
singleInfoWindow : true
});
geoXml.parse('http://DomainName/GeoSystem/redrawKML');
The following is My KML Content which will be produced by my rest service ( http://DomainName/GeoSystem/redrawKML)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:ns2="http://www.google.com/kml/ext/2.2" xmlns:ns3="http://www.w3.org/2005/Atom" xmlns:ns4="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
<Document>
<name>My KML Document</name>
<Placemark>
<name>Fort Worth</name>
<open>1</open>
<description>Fort Worth , Dallas</description>
<ExtendedData>
<Data name="GeoRegionId">
<value>1</value>
</Data>
<Data name="PolygonId">
<value>132</value>
</Data>
</ExtendedData>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>-97.47551,32.778615 -97.45079,32.79651 -97.437744,32.798242 -97.420578,32.806322 -97.417145,32.813824 -97.34848,32.843251 -97.338867,32.842674 -97.317581,32.838635 -97.292862,32.838058 -97.264709,32.839212 -97.229691,32.840943 -97.207718,32.831135 -97.206345,32.814978 -97.211838,32.802859 -97.212524,32.758985 -97.224884,32.739927 -97.225571,32.716822 -97.240677,32.691977 -97.239304,32.667125 -97.245483,32.661922 -97.281876,32.6625 -97.304535,32.668859 -97.334061,32.663656 -97.380066,32.671749 -97.402725,32.684464 -97.459717,32.683308 -97.47139,32.695444 -97.478943,32.720288 -97.482376,32.741082 -97.47551,32.778615
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</kml>
Got the answer.
If KMLLayer of google maps API3 has to display contents, The KML File should be in PUBLICALLY ACCESIBLE. Then only the google server can parse the file and will render it in the google maps.
Since I am developing in my local environment. Google Server can not parse the KML File which i am providing. That is why the contents are not rendered in the Google maps.
Have you checked the KML limits of Google Maps API v3 ? If you surpass the limit on feature quantity or file weight, then nothing will be displayed.
Edit:
I uploaded your kml to my public dropbox folder. And I'm loading it fine with
var fortw = new google.maps.KmlLayer({
url: 'https://dl.dropboxusercontent.com/u/3133731/fortworth.kml',
map: map
});

How to get directions in iOS 6 on new Apple Maps?

I've an app builded for iOS < 6, and before it all the features work perfectly. Now I've used a switch that recognizes the iOS installed on a device and then my app opens the correct maps to get directions from the local position to another (some pins on the map). The problem is that before iOS 6, the app opens the native maps and show the route to the user. Now, If the device uses iOS 6, the app opens the Apple Maps but shows a pop-up with something like "Impossible to get direction between this 2 positions". Why? Can someone helps me to solve this problem?
Here how I pass the coordinate to maps from a disclosure button:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
[self.navigationController pushViewController:[[UIViewController alloc] init] animated:YES];
if (SYSTEM_VERSION_LESS_THAN(#"6.0")) {
NSString* addr = [NSString stringWithFormat:#"http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude];
NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
}
else {
NSString* addr = [NSString stringWithFormat:#"http://maps.apple.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude];
NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
}
Whilst you can use the URL method for maps (http://maps.apple.com/...), I've found it not to be great when presenting specific locations. Your best bet would be to use MapKit objects on iOS 6 and above.
Example:
CLLocationCoordinate2D location;
location.latitude = ...;
location.longtitude = ...;
MKPlacemark* placemark = [[MKPlacemark alloc] initWithCoordinate:location addressDictionary:nil];
MKMapItem* item = [[MKMapItem alloc] initWithPlacemark:placemark];
//... Any Item customizations
NSDictionary* mapLaunchOptions = ...;
[item openInMapsWithLaunchOptions:mapLaunchOptions];
This will open Apple Maps directly, with the item you have provided.
In order to deal with directions, use the MKLaunchOptionsDirectionsModeKey launch option, and provide the start and end map items via:
[MKMapItem openMapsWithItems:mapItems launchOptions:launchOptions];
Just to clarify the other answer, you have two options when giving directions: driving or walking. Here are the ways to do each one:
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude) addressDictionary:nil];
MKMapItem *destination = [[MKMapItem alloc] initWithPlacemark:placemark];
//This is for driving
[MKMapItem openMapsWithItems:#[destination] launchOptions:#{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving}];
//This is for walking
[MKMapItem openMapsWithItems:#[destination] launchOptions:#{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeWalking}];
More info from Apple's docs over here.

Blackberry: Passing KML file to Google Maps

I want to know that can I pass KML as a string to google map application?
Code snippet:
//KML String
String document = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><kml xmlns=\"http://www.opengis.net/kml/2.2\"><Document><Folder><name>Paths</name><open>0</open><Placemark><LineString><tessellate>1</tessellate><coordinates> -112.0814237830345,36.10677870477137,0 -112.0870267752693,36.0905099328766,0</coordinates></LineString></Placemark></Folder></Document></kml>";
//Invoke Google Maps
int module = CodeModuleManager.getModuleHandle("GoogleMaps");
if (module == 0) {
try {
throw new ApplicationManagerException("GoogleMaps isn't installed");
} catch (ApplicationManagerException e) {
System.out.println(e.getMessage());
}
}
String[] args = {document}; //Is this possible???
ApplicationDescriptor descriptor = CodeModuleManager.getApplicationDescriptors(module)[0];
ApplicationDescriptor ad2 = new ApplicationDescriptor(descriptor, args);
try {
ApplicationManager.getApplicationManager().runApplication(ad2, true);
} catch (ApplicationManagerException e) {
System.out.println(e.getMessage());
}
After much R&D...the answer that I found out was that - No, we cannot pass KML as string.
Google Maps Mobile accepts a URL parameter. This needs to be in the form of "http://" and could be either specific parameters (such as "http://gmm/x?....") or a KML file ("http://..../sample.kml").
You MUST parse your mapFile (KML, gpx, txt) IF using the GoogleMaps API.
if all you want is to see your KML file inside a googlemaps window, you can goto the standard http://www.googlemaps.com and inside the ADDRESS box, you put the complete http address of your kml file.
until april2012 this used to work perfectly and the sidebar would be populated correctly, with clickable items (clicking on sidebar entry [e.g. "point 1" would fly-to the equivalent location). as of may2012, this feature is working incorrectly.
IF you want to take things one step further, you can have a PHP page echo the kml (on the fly KML rendering from database or file). BUT, googlemaps will not refresh your dynamically generated output for 10 to 15 minutes.
PM me if you want some javascript GPX and TXT mapFile rendering for GoogleMaps API vs3