Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-30-2009, 11:23 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 8
SlumRf is on a distinguished road
Question Refresh MapView

Hi all !

I need help
I have an MapView with annotations. The annotation's location can change in real time. Every 5 seconds, my app get a XML file and change the mapview list annotation coordinates.
But the problem is : annotation's coordinates really change but map view needs a user action to refresh the map (moving, zooming in, zooming out, ...). So how could I do a automatic mapView refresh ? (something like [mapView refresh] would be perfect )

Thank you for your answers !
SlumRf is offline   Reply With Quote
Old 07-31-2009, 01:47 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 8
SlumRf is on a distinguished road
Default

up please
SlumRf is offline   Reply With Quote
Old 08-01-2009, 09:37 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Raleigh, NC
Posts: 75
bigdave1024 is on a distinguished road
Default

I too am very interested to know if there is a way to do this.
bigdave1024 is offline   Reply With Quote
Old 08-01-2009, 09:43 AM   #4 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 8
SlumRf is on a distinguished road
Default

I'm using image annotations instead of pins. If I try [mapView removeAnnotations:mapView.annotations] and rebuild annotations, I have red pins and no image.
I think the better way is to update the annotations coordinate. That's what i did, but the problem is still the same : it needs a map action from the user (scroll, zoom, etc ...)
SlumRf is offline   Reply With Quote
Old 08-01-2009, 09:49 AM   #5 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Raleigh, NC
Posts: 75
bigdave1024 is on a distinguished road
Default

Hi Slum,

I'm using the MapView to show the user's current location and place a pin at that location. Seems simple enough. The problem I'm having is when I load the view the map is shown however all the squares have a No Images message in them. However if I go back to my main menu and back in then the map is shown with the location zoomed in with a pin at the current location. Now granted I'm testing this on the simulator so when the map does load it zooms in on Apple's location in California. But I'm sure once I start testing on the iPhone itself it would zoom into the correct location.
bigdave1024 is offline   Reply With Quote
Old 08-01-2009, 09:59 AM   #6 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Raleigh, NC
Posts: 75
bigdave1024 is on a distinguished road
Default

After taking a look at the console it seems that the reverse geocoding is failing on the first view load and then completing successfully on the second view load.

Here is the relevant functions in mapView.m:

Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
	mapView.showsUserLocation = TRUE;
	mapView.mapType = MKMapTypeHybrid;
	mapView.delegate = self;
	
	// Region and zoom
	MKCoordinateRegion region;
	MKCoordinateSpan span;
	span.latitudeDelta = 0.2;
	span.longitudeDelta = 0.2;
	
	CLLocationCoordinate2D location = mapView.userLocation.coordinate;
	
	region.span = span;
	region.center = location;
	
	// Geocoder stuff
	
	geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:location];
	geoCoder.delegate = self;
	[geoCoder start];
	
	[mapView setRegion:region animated:TRUE];
	[mapView regionThatFits:region];
	[self.view insertSubview:mapView atIndex:0];
	
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error {
	
	NSLog(@"Reverse Geocoder Failed");
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
	
	NSLog(@"Reverse Geocoder completed");
	mPlacemark = placemark;
	[mapView addAnnotation:placemark];
	
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
	
	MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
	annView.animatesDrop = TRUE;
	return annView;
	
}
bigdave1024 is offline   Reply With Quote
Old 08-01-2009, 09:59 AM   #7 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 8
SlumRf is on a distinguished road
Default

Quote:
Originally Posted by bigdave1024 View Post
Hi Slum,

I'm using the MapView to show the user's current location and place a pin at that location. Seems simple enough. The problem I'm having is when I load the view the map is shown however all the squares have a No Images message in them. However if I go back to my main menu and back in then the map is shown with the location zoomed in with a pin at the current location. Now granted I'm testing this on the simulator so when the map does load it zooms in on Apple's location in California. But I'm sure once I start testing on the iPhone itself it would zoom into the correct location.
The simulator will place you on apple's location, it's normal. If you have a blue drill with a Current location label be sure it'll works on you iPhone.
SlumRf is offline   Reply With Quote
Old 08-01-2009, 10:05 AM   #8 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Raleigh, NC
Posts: 75
bigdave1024 is on a distinguished road
Default

Quote:
Originally Posted by SlumRf View Post
The simulator will place you on apple's location, it's normal. If you have a blue drill with a Current location label be sure it'll works on you iPhone.
Yeah I'm using a red pin, but I'm trying to resolve the problem where the map is not loading the first time the view is loaded - its failing reverse geocode. Like I mentioned before if I go back and then back into the mapView the map loads correctly without the No Images error in the background. Thats why I was thinking its either an issue on the simulator or maybe I should refresh the mapView.

Last edited by bigdave1024; 08-01-2009 at 10:09 AM.
bigdave1024 is offline   Reply With Quote
Old 08-03-2009, 11:51 AM   #9 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 36
wakka092 is on a distinguished road
Default

Quote:
Originally Posted by bigdave1024 View Post
Yeah I'm using a red pin, but I'm trying to resolve the problem where the map is not loading the first time the view is loaded - its failing reverse geocode. Like I mentioned before if I go back and then back into the mapView the map loads correctly without the No Images error in the background. Thats why I was thinking its either an issue on the simulator or maybe I should refresh the mapView.
I'm having these issues too. Adjusting your region and span settings (or just commenting them out) will let you see the default US view.
wakka092 is offline   Reply With Quote
Old 08-03-2009, 11:57 AM   #10 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Raleigh, NC
Posts: 75
bigdave1024 is on a distinguished road
Default

I figured this out last night. I ended up having to use CLLocation to save my latitude and longitude coordinates and passing those on to my MKMapView instance variable. So now when I load my map it zooms into the current location and drops a pin at that location and it works everytime. I'm not sure if that is Slum's problem as well, but that fixed it for me.
bigdave1024 is offline   Reply With Quote
Old 08-03-2009, 12:16 PM   #11 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 36
wakka092 is on a distinguished road
Default

Quote:
Originally Posted by bigdave1024 View Post
I figured this out last night. I ended up having to use CLLocation to save my latitude and longitude coordinates and passing those on to my MKMapView instance variable. So now when I load my map it zooms into the current location and drops a pin at that location and it works everytime. I'm not sure if that is Slum's problem as well, but that fixed it for me.
That's good. I don't know if Slum needed the reverse geocoding, but I do so I can grab the postal code from the placemark. That's my problem.
wakka092 is offline   Reply With Quote
Old 08-03-2009, 12:20 PM   #12 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Raleigh, NC
Posts: 75
bigdave1024 is on a distinguished road
Default

Quote:
Originally Posted by wakka092 View Post
That's good. I don't know if Slum needed the reverse geocoding, but I do so I can grab the postal code from the placemark. That's my problem.

Would you mind posting your code to grab the postal code from the placemark? This is also on my list of things to do.
bigdave1024 is offline   Reply With Quote
Old 08-03-2009, 12:25 PM   #13 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 36
wakka092 is on a distinguished road
Default

Quote:
Originally Posted by bigdave1024 View Post
Would you mind posting your code to grab the postal code from the placemark? This is also on my list of things to do.
Well, I'd check out the MKPlacemark reference. There's a lot of info accessible. But you have to rely on using the reverse geocoder to get that info. I would tell you more, but I'm stuck at the moment trying to get the geocoder to even work..
wakka092 is offline   Reply With Quote
Old 08-03-2009, 12:34 PM   #14 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Raleigh, NC
Posts: 75
bigdave1024 is on a distinguished road
Default

Quote:
Originally Posted by wakka092 View Post
Well, I'd check out the MKPlacemark reference. There's a lot of info accessible. But you have to rely on using the reverse geocoder to get that info. I would tell you more, but I'm stuck at the moment trying to get the geocoder to even work..
Did you see the code I had posted above? That is how I have my reverse geocoding working now.
bigdave1024 is offline   Reply With Quote
Old 08-03-2009, 12:41 PM   #15 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 36
wakka092 is on a distinguished road
Default

Quote:
Originally Posted by bigdave1024 View Post
Did you see the code I had posted above? That is how I have my reverse geocoding working now.
You haven't posted your code where you implement CLLocation. Would you please, if you don't mind? If I get my geocoding to work, I would gladly share with you how I get the placemark info (I have no clue if it works right now.)
wakka092 is offline   Reply With Quote
Old 08-03-2009, 12:47 PM   #16 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Raleigh, NC
Posts: 75
bigdave1024 is on a distinguished road
Default

Quote:
Originally Posted by wakka092 View Post
You haven't posted your code where you implement CLLocation. Would you please, if you don't mind? If I get my geocoding to work, I would gladly share with you how I get the placemark info (I have no clue if it works right now.)
Sure, however I'm not at my development workstation right now. Give me a few hours and once I am home I will post the code.
bigdave1024 is offline   Reply With Quote
Old 08-03-2009, 12:48 PM   #17 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 36
wakka092 is on a distinguished road
Default

Quote:
Originally Posted by bigdave1024 View Post
Sure, however I'm not at my development workstation right now. Give me a few hours and once I am home I will post the code.
Thanks!
wakka092 is offline   Reply With Quote
Old 08-03-2009, 04:51 PM   #18 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Raleigh, NC
Posts: 75
bigdave1024 is on a distinguished road
Default

Here is the code I use in the implementation file. It is a little different than what I had previously posted.

Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	
	mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
	mapView.showsUserLocation = TRUE;
	mapView.mapType = MKMapTypeHybrid;
	mapView.delegate = self;
	[self.view insertSubview:mapView atIndex:0];
	
	CLLocationManager *locationManager = [[CLLocationManager alloc] init];
	locationManager.delegate = self;
	locationManager.desiredAccuracy = kCLLocationAccuracyBest;
	
	[locationManager startUpdatingLocation];
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error {
	
	NSLog(@"Reverse Geocoder Failed");
}


- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
	
	NSLog(@"Reverse Geocoder completed");
	mPlacemark = placemark;
	[mapView addAnnotation:placemark];
	
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
	
	MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
	[annView setPinColor:MKPinAnnotationColorRed];
	annView.animatesDrop = TRUE;
	return annView;
	
}

#pragma mark -
#pragma mark CLLocationManagerDelegate Methods
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
	
	location = newLocation.coordinate;
	
	MKCoordinateRegion region;
	region.center = location;
	MKCoordinateSpan span;
	span.latitudeDelta = .005;
	span.longitudeDelta = .005;
	region.span = span;
	
	[mapView setRegion:region animated:TRUE];
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
	
	NSString *errorType = (error.code == kCLErrorDenied) ? @"Access denied" : @"Unknown Error";
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error getting location" message:errorType delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
	[alert show];
	[alert release];
}
Hope this helps.
bigdave1024 is offline   Reply With Quote
Old 08-03-2009, 04:52 PM   #19 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Raleigh, NC
Posts: 75
bigdave1024 is on a distinguished road
Default

And here is what my interface file looks like:

Code:
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#import <MapKit/MKAnnotation.h>
#import <MapKit/MKReverseGeocoder.h>


@interface GoToLocationViewController : UIViewController <CLLocationManagerDelegate, MKReverseGeocoderDelegate, MKMapViewDelegate> {
	
	MKMapView *mapView;
	MKReverseGeocoder *geoCoder;
	MKPlacemark *mPlacemark;
	
	CLLocationCoordinate2D location;
	
}
bigdave1024 is offline   Reply With Quote
Old 08-03-2009, 06:12 PM   #20 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 36
wakka092 is on a distinguished road
Default

Thanks Dave! My map's reflecting location properly. Now, it's VERY simple to find the ZIP/postal code. The only part of the code I changed was adding a IBOutlet to a label (zipLabel) although I'm sure you'd like to do so programatically and setting its text as the annotation's postal code. Let me know if I left something out!

Code:
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
	
	NSLog(@"Reverse Geocoder completed");
	mPlacemark = placemark;
	[mapView addAnnotation:placemark];
	mapView.userInteractionEnabled = YES;
	
	zipLabel.text = placemark.postalCode;
	
}
wakka092 is offline   Reply With Quote
Old 02-23-2010, 03:30 AM   #21 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 29
leeus is on a distinguished road
Default

Did you find a solution to the "Refresh"?
leeus is offline   Reply With Quote
Old 07-06-2010, 08:58 AM   #22 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 21
DarthVader007 is on a distinguished road
Default

Does anyone have a solution for this?

I need also a Map refresh, because of new Annotations are added when moving the mapview
DarthVader007 is offline   Reply With Quote
Old 08-06-2010, 07:23 AM   #23 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 3
divyaprasad86 is on a distinguished road
Default

good tutorial
divyaprasad86 is offline   Reply With Quote
Old 10-27-2010, 06:23 PM   #24 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 1
TrunkeTa is on a distinguished road
Default

I was looking for the refresh map and this solution works for me:
[self performSelectorOnMainThread:@selector(refreshMapa) withObject:nil waitUntilDone:false];

Hope it helps,

Regards.



Quote:
Originally Posted by SlumRf View Post
Hi all !

I need help
I have an MapView with annotations. The annotation's location can change in real time. Every 5 seconds, my app get a XML file and change the mapview list annotation coordinates.
But the problem is : annotation's coordinates really change but map view needs a user action to refresh the map (moving, zooming in, zooming out, ...). So how could I do a automatic mapView refresh ? (something like [mapView refresh] would be perfect )

Thank you for your answers !
TrunkeTa is offline   Reply With Quote
Old 04-06-2012, 07:16 AM   #25 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

I saw this thread when im looking for ways to refresh the MKMapView.

Unfortunately, it seems this thread was hijacked by somebody else with a different problem.

Anyway for those who are looking for way to refresh the mapview, use this code:

Code:
[mapKitView setVisibleMapRect:maprect];
rocotilos is offline   Reply With Quote
Reply

Bookmarks

Tags
actions, coordinates, google, maps, refresh

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 329
11 members and 318 guests
chiataytuday, coolman, givensur, guusleijsten, ipodphone, jbro, mediaspree, mottdog, mtl_tech_guy, Punkjumper, vilisei
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,882
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:20 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0