iOS Apple Map native links - URL Scheme examples - ios

In one of my projects I'm capturing the Lat/Long coords in a core data store, and later on providing this information in an email with Attached PDF.. On the receiving end, I'd like the convenience of another iPhone user to be able to click on the link, and go to that location in Apple Maps
I find the native apple map comes up, but it's simply an open map view w/no pin:
NSString *appleLink2 = [NSString stringWithFormat:#"http://maps.apple.com/maps
ll=%#,%#",self.lat,self.lon];
I'm creating the clickable in a common fashion with a CGRect, and NSURL
It appears on the surface that I should probably get the street address instead of the Lat/Long coords also, and use the address for better map resolution... Thoughts?
Also, I'm looking for examples of Apples URL Schemes to query strings mentioned in the Docs, but can't find any real examples... ll = , son =, t = , z =. I understand saddr and daddr, and am surprised that I can't find any reference or real examples anywhere.

If you want the pin to be placed on the map in Apple's Maps app, use a 'q' instead of 'll' in the URL:
NSString *appleLink2 = [NSString stringWithFormat: #"http://maps.apple.com/maps?q=%#,%#", self.lat, self.lon];

The following apple link has all details for the questions
http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/MapLinks.html

USE NSString for URL
NSString *appleLink2 = [NSString stringWithFormat:#"http://maps.apple.com/maps
ll=%#,%#",self.lat,self.lon];
NSURL *myUrl = [NSURL URLWithString:[appleLink2 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
Then use myUrl is as URL.

Related

Issue with brackets in affiliate-urls

I am using the Zanox affiliate program.
My url has the following structure:
ad.zanox.com/ppc/?foo&zpar0=[[bar]]
While i link from my native iOS-application and it will open the Safari the square double brackets "[[]]" are encoded into "%5B%5B%5D%5D" so that my link from above at Safari now looks like:
ad.zanox.com/ppc/?foo&zpar0=%5B%5Bbar%5D%5D
Objective-C:
_postUrl = #"ad.zanox.com/ppc/?foo&zpar0=[[bar]]";
NSString *button = [self htmlButtonWithTitle:#"Affiliate-Link" andURL:_postUrl];
Is there any possibility to keep the square double brackets?
My only workaround now is to use bit.ly for the affiliate link. So far this only affects Zanox platform for me. It's an extra (unwanted) redirect, but better than nothing. Any other ideas?

iOS - Pinterest Sharing Description Text not working if I send "&" in description text

I had implemented pinterest sharing code in my app as well. Its working fine. But problem arrives at one scenario see follow
Correct working:
[pinterest createPinWithImageURL:[NSURL URLWithString:imageUrl]
sourceURL:[NSURL URLWithString:[NSString stringWithFormat:#"%#",shareUrl]]
description:#"My Description"];
Then it will share Pinterest Description same My Description as per my expectation.
But when I send Description Test like :
[pinterest createPinWithImageURL:[NSURL URLWithString:imageUrl]
sourceURL:[NSURL URLWithString:[NSString stringWithFormat:#"%#",shareUrl]]
description:#"My Details & Description"];
Then it will share Pinterest Description like My Details.
My expected text here is My Details & Description this is trunks my string after & symbol.
What actually wrong happening with me please look at here.
AFAIK, Pinterest's Pin It SDK isn't open source, so it's difficult to find out what's really going on.
I would guess, however, that this method is creating a GET request under-the-hood that's incorrectly URL encoding the description parameter (perhaps they're using stringByAddingPercentEscapesUsingEncoding or some other naive method).
I'd recommend contacting the Pinterest SDK developers/maintainers to look into this.
As a quick fix, you might try URL encoding the & yourself. For example, you might try replacing & with %26, e.g.
NSString *description = // ...whatever it should be set to...
description = [description stringByReplacingOccurrencesOfString:#"&" withString:#"%26"];
However, this might actually lead to other problems as the Pinterest SDK is likely doing some sort of URL encoding and would likely encode the % symbol.
Another naive approach may simply be to replace & with the word and, such as
NSString *description = // ...whatever it should be set to...
description = [description stringByReplacingOccurrencesOfString:#"&" withString:#"and"];
Again, it's hacky, but it's a workaround for a bug that's likely in the underlying SDK.

Updating Current Location in Google Maps using UIWebview in iOS

I have a WebView I created in app which calls Google Maps Directions to plot out the route between the Current Location and a POI.
The entire google map with directions is loaded as soon as the webView loads. Now I need to update the map with my current location. As in, I want the flag/icon representing my current location to move along with the user while he is travelling. But the only way I seem to be able to do this so far, is reloading the entire map by calling the new location.
This is very expensive in both time/data usage. Is there a better way that I'm missing ?
Here's my code :
CLLocationCoordinate2D destination = { 37.773768,-122.408638 };
NSString *googleMapsURLString = [NSString stringWithFormat:#"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f&output=embed",
myLocation.coordinate.latitude, myLocation.coordinate.longitude, destination.latitude, destination.longitude];
NSURL *url=[NSURL URLWithString:googleMapsURLString];
NSURLRequest *requestObj=[NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
Someone please help !!!
Use the GeolocationMarker from the Google Maps API 3 Utility Library. It was created for this purpose.
u can use..
CLLocationManager for getting user's location
UIWebview is not use for location fetching..

Finding a url in NSString

How can I search a NSString for a url in Xcode iOS?
For instance, If scan it for
HTTP://
and detect where the end of that url is and return the url string.
NSSearchFieldCell Class Reference
is only available on Mac development.
Check out this link I think it should be work NSDataDetector

Add address annotation when finding route via google maps api

I'm using google maps to get directions from one place to another. Here is the code
NSString *mapAPIString = [NSString stringWithFormat:#"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f",
sourceAddress.coordiate.latitude,
sourceAddress.coordiate.longitude,
destAddress.coordiate.latitude,
destAddress.coordiate.longitude,
];
NSURL *url = [[NSURL alloc] initWithString:mapAPIString];
[[UIApplication sharedApplication] openURL:url];
The code works perfect. But both addresses are marked as 'Unknown address' in iOS Map App. Is it possible to add custom title for each address ?
iOS 6 is still under NDA, but if you have access to the docs have a look at them and you will probably find useful information for this problem.

Resources