How to update location markers in map

Hello ,

I am planning to track the location of the users and show in the marker.

For that I am planning to store the location data inside the user collection like below

{
	"_id" : "yjDLZSnduspNrN65x",
	"createdAt" : ISODate("2015-12-04T09:03:12.940Z"),
	"services" : {
		"password" : {
			"bcrypt" : "$2a$10$U0oCTalo./JZb2LwtAAjhe1aIaElRQEL6Pbx.hoCz8wdI0GBOR3Ga"
		},
		"resume" : {
			"loginTokens" : [
				{
					"when" : ISODate("2015-12-04T10:15:32.534Z"),
					"hashedToken" : "kFS3/feRsYCDU1V2noyjn/zdAbKMgZTs+9Dbbt+yiIM="
				},
				{
					"when" : ISODate("2015-12-04T11:12:06.923Z"),
					"hashedToken" : "XVh+QSh0rUG2NEtEUULz+S1PD9UFLparkFWNIzHDTZY="
				}
			]
		}
	},
	"emails" : [
		{
			"address" : "dinesh3@complitech.net",
			"verified" : false
		}
	],
	"profile" : {
		"firstName" : "dinesh3",
		"lastName" : "dinesh3",
		"location" : {
			"latitude" : 22.4,
			"longitude" : 71.87
		}
	}
}

As I am using the Angular google maps plugin which accepts the data in the form of

$scope.markers = [{
    latitude: 40.1451,
    longitude: -99.6680
    id: '12411asdgashgah1241'
}, {
    latitude: 40.1451,
    longitude: -99.6680
    id: '12411asdgashgah1241'
}]

I used following publish pattern for that but still I have to remove the profile wrapper with help of underscore library to get only lat,long.

Meteor.publish(“locations”, function(users) {
return Meteor.users.find( {–Query According to zoom level—},{‘services’:0,‘emails’:0,‘createdAt’:0} );
});

Now Question is ,

–> Is there any way to create kind of publish-subscribe that has only those parameters that i wants?
–> If I zoom out to the last level where whole map will be visible , then all the users will be seen in the map , and that will creates issues in performance on client side as well as server side. I have used marker clusters in client side, Is there any way to set the maker clustering from the server side as well , If yes how can I ?

I’d suggest at the very least using the fields option to find, as mentioned in the rough draft of the Meteor guide here: http://guide.meteor.com/security.html#fields

You’ll still need to use underscore to transform the data into the right format, but at least you won’t send extra data to the client.

Also, to make this work properly you should not store location inside profile, but as a top-level field on the user document. See more here: http://guide.meteor.com/collections.html#Designing_your_data_schema

I think there’s no simple way to get this to update in real time with good performance. I’d suggest having a separate collection with marker clusters, and updating that periodically. Is it even useful for users to be able to see such a map? Another option could be to simply limit the amount that you can zoom out.

Hi @sashko Thanks for the great answer and great reference links.

1 Like