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
Solved

Need help displaying GPS location on MAP

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

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…
A brief look into what is, how to use, and how to make GIFs
The goal of this video is to provide viewers with basic examples to understand recursion 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.

856 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