Map of mobile user locations, updated automatically

We had this request the other day: can you display a map of the locations of users that recently logged onto our system, updating their map positions as they move about? Can the map be centered either on the viewer's location (shown by a different marker) or on the user that last logged in?

Let's see. Most of this requirement is easily implemented via the IP Geolocation Views and Maps module. All you need to do is select a way to attach a location storage field to the user account entity, either by attaching latitude and longitude plain text fields at admin/config/people/accounts/fields or by employing one of the various modules available for this: Geofield, Geolocation (Field), Location (with the submodule User Locations enabled) or GetLocations (with Getlocation Fields enabled). This will allow every user to set their initial location on their user profiles.
The resulting locations can then be collated by creating a View (of "Users" rather than "Content"). In the View select Map (Google, via IP Geolocation) for the format, complete the settings panel when prompted and you have a map of user locations. (Note: all of this also works with OpenLayers and Leaflet). You may include additional fields in your view (e.g. user name, last access etc). These will appear in the location marker balloons when clicked, unless explicitly excluded. One such field you may want to include is the distance of each user to the viewer. See the FAQ on the IP Geolocation Views and Maps project page for examples.

To address the second part of the requirement, the automatic update of the user location upon login, we developed a small module, named IP Geolocation User (attached). This module takes advantage of the HTML5 (i.e. GPS) location retrieval facility of IP Geolocation Views and Maps to auto-populate at login an additional field, say "City", which you also add to the user profile (at admin/config/people/accounts/fields) to hold the city/suburb/locality. The field may be edited by the user after login. If you include this field in your View, it will be displayed in the marker balloons on your map. Naturally you can also expose City as a filter on your View thus allowing your map to zoom in on the selected City. Or depending on the location storage module you use, you may want to filter by proximity.

If you have a lot of users on your system, you'll probably want to limit the number of locations displayed by restricting the number of View results to say 50, and ordering these by "User: Last access" (descending). This will then return the most recent login first in the View and thus as the center of the map, if you configured your View to do so.

File under: 

Done in 60 seconds: a location based service example using IP Geolocation

Read More »