?
Solved

Need help displaying GPS location on MAP

Posted on 2010-08-25
4
Medium Priority
?
1,789 Views
Last Modified: 2013-11-25
I'm not to iPhone development... so I'm still learning...

I'm creating a simple iPhone app to display my current location on the map.

I'm using this tutorial to see how I can display the map on the iPhone... but the location (lat, long) is hard coded.

http://blancer.com/tutorials/i-phone/76877/mapkit-example-in-iphone/

Everything works fine...

Now I found another tutorial that gets your location using the GPS..

http://www.vellios.com/2010/08/16/core-location-gps-tutorial/


My question is, since in the second tutorial they display the information on labels I was wondering how can I pass that information back to the map.

Here is the code that I need to update. How can I create a variable to replace the region information with the data collected from the iPhone GPS...

Thanks...

- (void)viewDidLoad {
    [super viewDidLoad];
       
        [mapView setMapType:MKMapTypeStandard];
        [mapView setZoomEnabled:YES];
        [mapView setScrollEnabled:YES];
        MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
        region.center.latitude = 22.569722 ;
        region.center.longitude = 88.369722;
        region.span.longitudeDelta = 0.01f;
        region.span.latitudeDelta = 0.01f;
        [mapView setRegion:region animated:YES];
       
        [mapView setDelegate:self];
       
        DisplayMap *ann = [[DisplayMap alloc] init];
        ann.title = @" Kolkata";
        ann.subtitle = @"Mahatma Gandhi Road";
        ann.coordinate = region.center;
        [mapView addAnnotation:ann];
}

Open in new window

0
Comment
Question by:Medrise
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 2

Expert Comment

by:tisaksen
ID: 33520236
You need to do that in the CLLocationManagerDelegate method locationManager:didUpdateToLocation:fromLocation:

Then just use the data you get in that method to create your region struct.
0
 

Author Comment

by:Medrise
ID: 33522528
Thanks, I will try that later today...
0
 

Author Comment

by:Medrise
ID: 33526748
I moved the information to the locationManager:didUpdateToLocation

but now I get the world map, and not the location I need.

Here is the code.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	//GET CURRENT LOCATION
	CLController = [[coreLocationController alloc] init];
	CLController.delegate = self;
	[CLController.locMgr startUpdatingLocation];
}

- (void)locationUpdate:(CLLocation *)location {
	//latitudeLabel = [NSString stringWithFormat:@"%f", location.coordinate.latitude];
	//longitudeLabel = [NSString stringWithFormat:@"%f", location.coordinate.longitude];
	
	[mapView setMapType:MKMapTypeStandard];
	[mapView setZoomEnabled:YES];
	[mapView setScrollEnabled:YES];
	
	MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
	
	region.center.latitude = location.coordinate.latitude;
	region.center.longitude = location.coordinate.longitude;
	region.span.longitudeDelta = 1.04*(126.766667 - 66.95);
	region.span.latitudeDelta = 1.04*(49.384472 - 24.520833);
	
	[mapView setRegion:region animated:YES];
	
	[mapView setDelegate:self];
	
	displayMap *ann = [[displayMap alloc] init];
	ann.title = @" Kolkata";
	ann.subtitle = @"Mahatma Gandhi Road";
	ann.coordinate = region.center;
	
	[mapView addAnnotation:ann];
}

Open in new window

0
 
LVL 2

Accepted Solution

by:
tisaksen earned 2000 total points
ID: 33528132
I guess locationUpdate is called by the delegate method I mentioned.
Anyway try this:

#define kZoomRadius 1000
// create map region
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location.coordinate, kZoomRadius, kZoomRadius);
// for correcting map aspect view
MKCoordinateRegion adjustRegion = [mapView regionThatFits:region];
// finally set the map region
[self.mapView setRegion:adjustRegion animated:YES];
            
where kZoomRadius is in meters
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let Bitmoji into your life. Now is the time to learn a new language of smartphone messaging with this brief introduction.
After hours on line I found a solution which pointed to the inherited Active Directory permissions . You have to give/allow permissions to the "Exchange trusted subsystem" for the user in the Active Directory...
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question