Solved

Need help displaying GPS location on MAP

Posted on 2010-08-25
4
1,777 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
  • 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 500 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
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 opening and writing to files in the C programming language.

772 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