4

I have two view controllers: tweetViewController and MapViewController. The former is for user to post a tweet, and in it I use CLLocationManager to get user's location. Once locationManager:didUpdateToLocation:fromLocation: is called, I got "locationA", I'll remind user that his location has been set.

User can just post the tweet with "locationA". Or change the location manually (in case the location is not accurate enough) by clicking the location info. In this case, MapViewController is pushed, and there is an draggable pin annotation associated with locationA fall down to the map. I found the pin is hundreds of meters apart from where I am. Then, I set mapView.showUserLocation = YES. And I found the blue bubble's location is much more accurate than the pin. So, my question is how can I get mapView's userLocation in the tweetViewController rather than the location from CLLocationManager.

I'm in China, I've been searching for the same problem. Some people say map in China is transformed, so then there must be an offset. Any suggestion to deal with the problem? Thanks in advance.

iHunter
  • 6,205
  • 3
  • 38
  • 56
Ronnie Xiang
  • 71
  • 1
  • 6
  • Did you correctly set your location manager accuracy and distance filter settings? normally the defaults give the best accuracy. And are you also correctly updating the location based on the delegate events? consider intact that when you start updating location using CLLocationManager it may happen that the first returned location is highly inaccurate due to successive approximations (cellular signal first, GPS signal later) or because it just got the last known location (it could be hours or days old): always check the "newLocation" timestamp and compare it with current date. – viggio24 Jan 10 '12 at 21:23
  • I set desiredAccuracy = kCLLocationAccuracyBest and distanceFilter = 5.0f, which I think is accurate enough. I can get the delegate method called several times, as in five times and then the location is stable. no more call of the delegate. Then I push the mapViewController. But still, the locationManager's location is hundreds of meters apart from the mapView's userLocation... Any clue? – Ronnie Xiang Jan 11 '12 at 15:44

2 Answers2

2

Finally, I use a MKMapView instance to solve this problem.

Setting

mapView.showUserLocation = YES/NO; //to start/stop locating.

Using

-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation 

to get the user location. In my controller, mapView is not shown, it's only used to get user location and the location is more accurate than which i get from locManager.

Pawan Rai
  • 3,434
  • 4
  • 32
  • 42
Ronnie Xiang
  • 71
  • 1
  • 6
-1

CLLocationManager uses the same data across all of its instances. MKMapView uses CLLocationManager's data internally. That said the solution to do what you want to do is let MKMapView do its own thing with regards to showUserLocation:. At the same time, create an instance of CLLocationManager and its delegate.

The delegate messages will give you the GPS coordinate location of MKMapView's blue pin. Everything will be in sync with each other.

iHunter
  • 6,205
  • 3
  • 38
  • 56
Vinay Jain
  • 2,644
  • 3
  • 26
  • 44
  • Hi Vinay, thanks for your answer. I still have a question, in my case, there will be no mapViewController if user doesn't click "change location" button. Also, I wonder why the two coordinates is different if using the same CLLocationManager's data? Is it said MKMapView do some adjustment for the coordinate? – Ronnie Xiang Jan 10 '12 at 16:00
  • Would be nice if you referred your answer. Refer: http://stackoverflow.com/a/2319673/3826773 – orhankutlu Mar 20 '16 at 20:13