How to get a map view in an iPhone app - iphone

How can I get this kind of map view in my application?
Any examples?

You'll need to use an MKMapView. For the popup, you'll need an annotation. Looking at the MKMapView documentation should get you pretty far..

You should be using MKMapView - as donkim mentioned do some reading on MKMapView, taht would get you pretty far. You can use MKAnnotations for the maps annotations. You can google for "custom annotations" if you want to want to use custom images for annotations.
You can refer to this post that i posted a while ago for a memory leak, but it pretty much has the code to show annotations on the map. I have borrowed the code from internet too...

I guess I need to call this... in
//NSString *latlong = [[NSString stringWithFormat:#"%f, %f", 52.366428f,4.896349f] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//........for destination location.
//NSString *dlatlong = [[NSString stringWithFormat:#"%f, %f", coordinate.latitude, coordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//for the current location. this. where coordinate is CLLocationManager2D.
//NSString *url = [NSString stringWithFormat: #"http://maps.google.com/maps?ll=%#&saddr=%#&daddr=%#",
//latlong, latlong, dlatlong];
need not to use mkmapkit.

There is a easier way of show a location on the map, however this approach will not implement a map view inside your application but it will open the map application.
[[UIApplication sharedApplication] openUrl:#"http://maps.google.com/maps?q=Oslo"];
After the q- parameter key you can write the same string as you normally write in google maps specifying the address. Read the documentation for UIApplication class for more information on this. Note, this will also automatically make a annotation for the location.
Just mention this because others may find this a useful if they don't need the map inside the application.
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html
Here is a list of other parameters:
http://mapki.com/wiki/Google_Map_Parameters

Related

Make phone call on iPhone and take user back to app? (UIWebView does it)

I used this code to make phone call:
NSString *phoneNumber = [#"tel://" stringByAppendingString:mymobileNO.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
and when the call ends, it does not take user back to the app. However, if I show a website in UIWebView and there is a phone number in the website(ie UIWebView recognises it), and if I tap that phone number link to make phone call, I will be taken back to the app when the call finishes.
My preliminary thinking is that the UIWebView does something internally like a deep link to the Phone app then another deep link inside the deep link to take the user back to the app. But I'm not sure. Is there a way to implement this feature?
Thanks!
You need to use the telprompt URL, not tel.
So:
NSString *phoneNumber = [#"telprompt://" stringByAppendingString:mymobileNO.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
This will also give the user a confirmation box before calling the number.
Edit:
This question covers the same issue.
Edit 2:
For those wondering if this URL will result in rejection from the App Store, the answer is generally no. The greater risk is that Apple will suddenly stop supporting the telprompt scheme. As explained by this article, there is a slightly 'safer' way of implementing telprompt with UIWebView (which uses telprompt internally, even if you call it with tel). The relevant code from the article shows how using the documented tel scheme can still give you the effect of telprompt:
+ (void)callWithString:(NSString *)phoneString {
[self callWithURL:[NSURL URLWithString:[NSString
stringWithFormat:#"tel:%#",phoneString]]];
}
+ (void)callWithURL:(NSURL *)url {
static UIWebView *webView = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
webView = [UIWebView new];
});
[webView loadRequest:[NSURLRequest requestWithURL:url]];
}
(Code taken from the article reference in my second edit)
The website: http://www.raizlabs.com/dev/2014/04/getting-the-best-behavior-from-phone-call-requests-using-tel-in-an-ios-app/ has a discussion of whether to use telprompt (undocumented, Apple could potentially change the API without notice), and instead using a category that sends the number to a web view which opens it using telprompt. This has the advantage of not breaking if Apple does something odd.

Opening iPhone Map into our iPhone App as a one of View?

In My Application I Want use Native iPhone Application. For this purpose i get the code as below
UIApplication *app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString: #"http://maps.google.com/maps?q=London"]];
It is Working Fine. But it will come outs from the My App. I want Show this is as one of my screens such like We opening Camera in Our apps as a Screen. Similarly i want to show iPhone Native App as a one of my View in My Application.
You cannot show another app as a direct view in your application. Instead you'll need to add the MKMapKit framework to your project, make a new UIViewController in your project and in Interface Builder add in the MapKit UI element. You can find tutorials online on how to use MapKit in your app to load specific areas on the map and do really neat things with it.
EDIT:
http://www.raywenderlich.com/2847/introduction-to-mapkit-on-ios-tutorial
You need to use MKMapView if you want a native map.
If you want to pass it a location like that you will also need to do some geocoding. Apple provide all of these API's but it isn't one line of code!
I suppose that you dont want to use MKMapKit as you didn't mentioned. If you want to show a web page in your app with request URL then you can do it with UIWebView.
You can load your request URL in web view as :-
NSString * urlStr = #"http://maps.google.com/maps?q=London" ;
NSURL *url = [NSURL URLWithString:urlStr];
[webview loadRequest:[NSURLRequest requestWithURL:url]];
(2) i want to show iPhone Native App as a one of my View in My Application
For that you can NOT.

Google map Implementation in Iphone

I already implemented google mapping functionality in my iphone application.It works fine but if the location to search is wrong string then it maps a location and it redirects to current location only after the search button clicks. How to implement that if the location is wrong then directly go to the current location? My code is like below
NSString *urlString = [[NSString stringWithFormat:#"http://maps.google.com/maps?z=14&q=%#",message] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
please give me a solution as soon as possible
Thanks in advance
Since you lose control the moment you leave your app, you should always perform the validity check before opening the URL by passing message to a CLGeocoder or a 3rd party Geocoder .
CLGeocoder Class Reference
Basically query for the location string inside your app, then format your url accordingly.

Xcode google map navigation

I currently have an application which will drop pins onto various points of interest on a map, all done programmatically on the iPhone.
What I am aiming to get done now is to allow a user to navigate to that location and get turn by turn directions by calling up the built in navigation tools on the iPhone.
Is there anyway that I can do this? I've scoured the developer center and searched both google and here and couldn't find anything about this.
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", start.latitude, start.longitude, end.latitude, end.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURLString]];
}

Using Current Location from Location Manager in a Google Maps openURL?

Been looking into this for a while today however I can't seem to get my head around how to get the users current location into a Google Maps URL to open the Google Maps app with directions populated.
I've taken this code from another tutorial and added it into my app. I need to get the "start" lat/lng from the below into my IBAction to open the Google Maps app.
- (void)locationUpdate:(CLLocation *)location {
// Lat/Lng of user (Needs to be sent to IBAction for btnDirections)
CLLocationCoordinate2D start = { location.coordinate.latitude, location.coordinate.longitude };
}
The below is my IBAction for my "Get Directions" button.
- (IBAction) onButtonClick:(id) sender {
if(sender == btnDirections) {
CLLocationCoordinate2D destination = { 52.48306771095311, -1.8935537338256836 };
NSString *googleMapsURLString = [NSString stringWithFormat:#"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f",
newLocation.coordinate.latitude, newLocation.coordinate.longitude, destination.latitude, destination.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURLString]];
}
}
I have done this previously in another app, however that view included a map showing the user location which allowed me to get the lat/lng easily.
Thanks in advance.
Simply pass "Current+Location" as a parameter to the google maps application:
http://maps.google.com/maps?saddr=Current+Location&daddr=Heathrow+Airport+London
In my code, I have an URL of the format :
http://maps.google.com/maps?daddr=%f,%f&saddr=%f,%f
(So that's 'maps' added from yours).
Other than that, you can setup your location request to stop after a set precision, did you setup precise enough for your purpose?
Oh, last note, getting current location might not work in simulator.
You need to make the user's current location available to the onButtonClick: method. You are creating the start structure on each location update, but you are never making it available outside of that method.