Discussion Forums  >  Maps, Device Location, Tracking

Replies: 19    Views: 333

Kristian_N
Code is Art
Profile
Posts: 91
Reg: Oct 27, 2011
Copenhagen
2,610
03/12/14 02:57 AM (10 years ago)

Location Map: show users location to a given point

Hi, I have been using the plugin "Location Map" several times and it works very well showing any number of locations on a map. However, I could use a little feature that allowed the users location to show up on the map showing the direction of the user towards a given point. For instance: A maps shows the locations of tv-transmitters in a given area. The users locations is shown on the map and the user can see in which direction he/she has to turn to face the transmitter. Is this possible in the current version or is it possible to modify it to do this? Kind regards, Kristian Nielsen
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
03/12/14 03:17 AM (10 years ago)
Hi Kristian, I put this in a custom map for someone. It acts liek apple maps compass so it won't point but it will spin the map around so it faces. Put this in the plugin in the same method where it calls for update user location. It's only one line of code [map setUserTrackingMode:MKUserTrackingModeFollowWithHeading]; I'm not at a mac you will probably have to swap map to mapView or whatever it is declared to I'm sure it would be possible to have just the arrow point the methods must be there. I just haven't done it Good luck
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/12/14 03:30 AM (10 years ago)
That's sweet, Kittsy :) Cheers! -- Smug
 
Kristian_N
Code is Art
Profile
Posts: 91
Reg: Oct 27, 2011
Copenhagen
2,610
like
03/12/14 03:57 AM (10 years ago)
Hi Andy, You are a genious :)! I must be buying you a beer - is Liverpool playing ManUtd soon ? Thanks! Kristian
 
farcat
buzztouch Evangelist
Profile
Posts: 1008
Reg: Jan 27, 2012
France
13,230
like
03/12/14 01:09 PM (10 years ago)
That's a keeper, thanks Kittsy. Farcat
 
LevensGardener
Aspiring developer
Profile
Posts: 220
Reg: Sep 30, 2012
Kendal
10,450
like
03/13/14 12:41 AM (10 years ago)
Anyone had a go at this? I'm trying to add at line 242 ish in BT_screen_map.m It throws errors whatever I try- semantic issues, bad receiver types etc. Any ideas?
 
LevensGardener
Aspiring developer
Profile
Posts: 220
Reg: Sep 30, 2012
Kendal
10,450
like
03/13/14 01:36 AM (10 years ago)
[self.mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES]; added at line 529 ish builds OK. It even gets you to calibrate your compass when opening the map. It doesn't auto align the map however. I feel I am getting halfway there. Any ideas?
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
03/13/14 03:49 AM (10 years ago)
It has been a while Chris will try and take a look, it might need a delegate or another line, it was a few months ago, pre 3.0
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
03/13/14 11:42 AM (10 years ago)
add this line in BT_screenMap.m around line 650 [self.mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading]; place it directly under self.mapView.userLocation.title = @"Loading location..."; so it looks like this //return the userLocation marker, or the customized view for this location if(annotation == self.mapView.userLocation){ self.mapView.userLocation.title = @"Loading location..."; [self.mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading]; //appDelegate tutorialapp_appDelegate *appDelegate = (tutorialapp_appDelegate *)[[UIApplication sharedApplication] delegate];
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
03/13/14 11:42 AM (10 years ago)
notice how the tracking mode has only been added when there is a user location.
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
03/13/14 12:17 PM (10 years ago)
You may now notice that when you move the map with your finger it resets. I advise using the user location button on the navbar and adding the same line of code in the -(void)centerDeviceLocation method like this around 570 mark //centers device location -(void)centerDeviceLocation{ [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"mapView:centerDeviceLocation %@", @""]]; //turn on user location it wasn't already if(!self.mapView.showsUserLocation){ [self.mapView setShowsUserLocation:TRUE]; } [self.mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading]; << Here I am //we may not have a device location... (ignore simulator values, their bogus!) if(self.mapView.userLocation){ //convert lat/lon to strings so we can test the length.. NSString *tmpLat = [NSString stringWithFormat:@"%f", self.mapView.userLocation.coordinate.latitude]; NSString *tmpLon = [NSString stringWithFormat:@"%f", self.mapView.userLocation.coordinate.longitude]; if([tmpLat length] > 3 && [tmpLon length] > 3){ //simulator is -180.000000 if(self.mapView.userLocation.coordinate.latitude != -180.000000){ //center on location CLLocationCoordinate2D tmpLocation; tmpLocation.latitude = self.mapView.userLocation.coordinate.latitude; tmpLocation.longitude = self.mapView.userLocation.coordinate.longitude; [self.mapView setCenterCoordinate:tmpLocation animated:TRUE]; //select the one and only annotation so the bubble shows [self.mapView selectAnnotation:self.mapView.userLocation animated:TRUE]; //zoom in [self.mapView setCenterCoordinate:tmpLocation zoomLevel:15 animated:YES]; } } } }
 
LevensGardener
Aspiring developer
Profile
Posts: 220
Reg: Sep 30, 2012
Kendal
10,450
like
03/14/14 07:55 AM (10 years ago)
Thanks for this Kittsy. The map is re-orientating now when you touch that user location button. Just not sure it is doing as I expected however. I thought perhaps it would align screen to reality, or spin round to face the pin-point 'destination'. Not sure it is doing either at present. Seems to be pointing north arrow to top left of screen whichever way round I hold the phone, or wherever I put the map pin. I'll experiment a little further...
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
03/14/14 08:00 AM (10 years ago)
It's a compass it will work the same as in the apple maps. I'm sure there is some further tweaking that could be done, but not today for me lol
 
LevensGardener
Aspiring developer
Profile
Posts: 220
Reg: Sep 30, 2012
Kendal
10,450
like
03/14/14 08:01 AM (10 years ago)
No worries. Thanks for looking... Chris
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
03/14/14 08:14 AM (10 years ago)
But I do have to disagree slightly, if there is a pin on the map and I'm looking forward and the pin is behind me,when I turn around with the phone the pin is in front of me on the map. What else would you want it to do?
 
LevensGardener
Aspiring developer
Profile
Posts: 220
Reg: Sep 30, 2012
Kendal
10,450
like
03/14/14 08:14 AM (10 years ago)
Oh Kittsy! I'm an idjit!! Just took my phone out of its case and it works like a dream - it has a magnetic catch on it. doh!!!
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
03/14/14 08:15 AM (10 years ago)
ha ha, I was awfully confused
 
LevensGardener
Aspiring developer
Profile
Posts: 220
Reg: Sep 30, 2012
Kendal
10,450
like
03/14/14 08:15 AM (10 years ago)
Perfect now Mr Kitts. Please accept my super humblest apologies....
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
03/14/14 08:17 AM (10 years ago)
It's okay I looked and replied then thought after, what else would it do. Then though well if we put an arrow as the user location pin, and have it point to the nearest pin. Anyway stop making me procrastinate I've got uni assignments to do, bags to pack, plugins to mod ARRRRGGGGGHHHH
 
LevensGardener
Aspiring developer
Profile
Posts: 220
Reg: Sep 30, 2012
Kendal
10,450
like
03/14/14 08:23 AM (10 years ago)
That is an interesting idea. Don't let me distract you further though! Thanking you....
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.