|
|
#1 |
|
Mapkit ios6 example.
Hello,
I am using the Mapkit in iOS6. I added the viewwillappear method and passed my current co-ordinates. Code:
#define METERS_PER_MILE 160.344
- (void)viewWillAppear:(BOOL)animated
{
CLLocationCoordinate2D zoomLocation;
zoomLocation.latitude = XX.657016;
zoomLocation.longitude = -XXX.369874;
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5 *METERS_PER_MILE, 0.5*METERS_PER_MILE);
[_mapView setRegion:viewRegion animated:YES];
_mapView.showsUserLocation = YES;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
}
Also i have 3 screens on my app. Second screen has the mapkit at the bottom left about the size of rubik's cube (3X3). So when i click a button on second screen and move to third screen( do my work on 3rd screen and click back) and come back to second screen it shows the location correctly(2nd screen->3rd screen ->2nd Screen).But there is no blue dot on it.Why?IF more information is needed please let me know. Thanks... Last edited by dejo; Nov 6, 2012 at 07:23 PM. Reason: Please use [code] tags. |
|
|
|
0
|
|
|
#2 |
|
This is in the Simulator, correct? It defaults to Apple Headquarters in Cupertino. If you want to change the location, visit the Debug > Location menu item.
__________________
|
|
|
|
0
|
|
|
#3 |
|
@dejo. Thanks.Yes,its in simulator. I did Debug->Location->menu item and changed to the given list there. It changes to each one correctly. How can i add my current location to it. Because it is recognizing this location, but
on back operation. Screen1->Screen2(mapkit is on this screen)->Screen3. So when i go back from screen 3 to screen 2 ..it shows( )..but not from Screen1 ->Screen2( ). Please help.
|
|
|
|
0
|
|
|
#4 |
|
Um, did you not notice the Custom Location... option? Use it to set it to your current location.
__________________
|
|
|
|
0
|
|
|
#5 |
|
Also, just one point, you have METERS_PER_MILE as 160.3. Shouldn't it be 1609.34? Just something to notice
__________________
2012 Mac Mini, 2.6 GHz, 16GB RAM, 1TB HDD ![]() 2.4Ghz 15" Macbook Pro ![]() 32 GB iPhone 4S : 16 GB iPod nano : 16 GB iPad 3 Nikon D60 : 18-55 mm VR : 55-200 mm VR |
|
|
|
0
|
|
|
#6 |
|
@Dejo. I cannot see a custom location option. All i can see are 12 locations London...brazil..and a add a GPX file. Where is it?Can you please point it to me?
|
|
|
|
0
|
|
|
#7 |
|
You don't see this (from the iOS Simulator NOT Xcode)?:
__________________
|
|
|
|
1
|
|
|
#8 |
|
@Dejo.Thanks.That was awesome.Now, i have another question. So i was referring to another problem also. So on my first load i.e i run the app,move from 1st screen to 2nd screen, the mapkit now shows my current location on a zoomed-out mode(World map), with a blue dot. But i go back to 1st screen and come back to 2nd screen, now this time it shows my location in zoomed in mode. What i mean it shows the two streets and a blue dot where i am right now. But on the second time. Why does it not show the first time? Am i missing an order of functions or something. Did it ever happen to you?If you have any information about this please share..Thanks again.
|
|
|
|
0
|
|
|
#9 | |
|
Quote:
__________________
|
||
|
|
0
|
|
|
#10 |
|
@Dejo.Ok. So, i checked the working of how the screen loads. First viewDidLoad is called then viewWillAppear and then didUpdateLocations is called.
viewDidLoad ->ViewWillAppear->didUpdateLocations. But i set the co-ordinates from the simulator like you said. Now eventhough i set them at runtime i want them to be set in ViewWilAppear. So that when i change the location to somewhere in viewwillappear it should point to that location. Also,zoom in mode. Is there any property that one has to set.Well it doesnt make sense, because on coming to the 2nd screen second time it zooms in to my location. So there is something missing on the first load. |
|
|
|
0
|
|
|
#11 | ||
|
Quote:
If so, that's not always possible, because it takes a while for the location manager to triangulate the user's position and the screen may already have appeared. You would want to delay setting of the view region until you have sufficient accuracy in the user's location then. If not, please describe in more detail what you are trying to do. I'm guessing that English may not be your first language and, if so, it may be harder for you to describe it properly. Quote:
P.S. Did you fix the issue with your value for METERS_PER_MILE yet?
__________________
|
|||
|
|
0
|
|
|
#12 |
|
@Dejo. Yes. I want to show show the region around the current user's location, wherever that may be, when the screen first appears. Yes i fixed the meters issue. And yes, English is not my first language.
![]() Code:
#define METERS_PER_MILE 1609.344
- (void)viewWillAppear:(BOOL)animated
{
CLLocationCoordinate2D zoomLocation;
zoomLocation.latitude = XX.657016;
zoomLocation.longitude = -XXX.369874;
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5 *METERS_PER_MILE, 0.5*METERS_PER_MILE);
[self.mapView setRegion:viewRegion animated:YES];
self.mapView.zoomEnabled = YES;
self.mapView.showsUserLocation = YES;
}
- (void)viewDidLoad
{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
}
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
MKAnnotationView *annotationView = [views objectAtIndex:0];
id <MKAnnotation> mp = [annotationView annotation];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate] ,500,500);
[mv setRegion:region animated:YES];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSString *latLongValue=@"";
int s=0;
CLLocation *location = [locations objectAtIndex:0];
NSLog(@"%f%f",location.coordinate.latitude,location.coordinate.longitude);
int degrees = location.coordinate.latitude;
double decimal = fabs(location.coordinate.latitude - degrees);
int minutes = decimal *60;
double seconds = decimal * 3600-minutes * 60;
NSString *lat = [NSString stringWithFormat:@"%d %d' %1.4f\"",degrees,minutes,seconds];
s = seconds;
latLongValue = [NSString stringWithFormat:@"%d %d %d %@",degrees,minutes,s,@" "];
NSLog(@"so far string is %@",latLongValue);
self.txtLatitude.text = latLongValue;
NSLog(@"lat is %@",lat);
degrees = location.coordinate.longitude;
decimal = fabs(location.coordinate.longitude - degrees);
minutes = decimal *60;
seconds = decimal *3600 - minutes *60;
NSString *longt = [NSString stringWithFormat:@"%d %d' %1.4f\"",degrees,minutes,seconds];
s =seconds;
NSString *longtValue= [NSString stringWithFormat:@"%d %d %d",degrees,minutes,s];
self.txtLongitude.text = longtValue;
latLongValue = [latLongValue stringByAppendingString:longtValue];
NSLog(@"the final value is %@",latLongValue);
NSLog(@"long is %@",longt);
[self.locationManager stopUpdatingLocation];
}
|
|
|
|
0
|
|
|
#13 |
|
Code:
zoomLocation.latitude = XX.657016; zoomLocation.longitude = -XXX.369874;
__________________
|
|
|
|
0
|
|
|
#14 |
|
@Dejo.
You can use your co-ordinates and check. If it works for you then please tell me where you made the changes. |
|
|
|
0
|
|
|
#15 |
|
Doesn't matter. The point is when those lines are executed, you probably don't yet know what the user's current location is. So, you can't set them in a meaningful way. Once you do know the user's location, with a certain amount of accuracy, then you can set the view region.
Now, what would be a good candidate delegate method that lets you know when the location manager has updated?
__________________
|
|
|
|
0
|
![]() |
|
| Tags |
| coordinates, ios6, location, map, mapkit |
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 08:43 AM.






I support the
). Please help.


2012 Mac Mini, 2.6 GHz, 16GB RAM, 1TB HDD 

Linear Mode
