Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need help displaying GPS location on MAP

Posted on 2010-08-25
4
Medium Priority
?
1,794 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Are you looking to clear some space on your phone for the latest iOS 8 update? Did you switch to Spotify so you no longer need to keep music native on your phone? Run out of space for taking photos while in the middle of vacation? Sometimes the quic…
Email is way too noisy, prone to hiding the important stuff, and really becoming unreliable for critical/timely communications. There are better ways to communicate.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

618 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