Is it possible to call Google Map API in server? If yes, how?
I would like to show only Markers that is 10 miles from the user Geolocation during publish. I did pass the user Geolocation parameter during subscribe however when I tried calling google in the server it says “google is not defined”
var arrPharma = [];
var arrayMarkers = Markers.find().fetch();
_.each(arrayMarkers, function (xmarker) {
if ( distancer( new google.maps.LatLng(origin[0], origin[1]), new google.maps.LatLng(xmarker.Lat, xmarker.Lng), 10 ) )
arrPharma.push(xmarker.pharma);
console.log(arrPharma);
});
Good question and very funny. That’s on my todo list for today.
I also plan to have some google api call from the server.
I need geo reverse encoding from the server.
If you’re talking geodesic distance, you should use mongo, it’ll be WAY faster. Store your location in standard JSON format & put an index on it. Then, you can do this all on your service with very little overhead and no external calls. If you have to use google on the server, you don’t call it via the javascript wrapper, but rather via a server call. That means you’ll be limited to 2500 calls on YOUR server IP, not the client IP, so the solution doesn’t scale. But seriously, don’t call google, it’s useless to make an external call to just do a geometry problem (see haversine & equirectangular distance formulas).
If you’re doing road distances, what you want is called an isodistance and those get real expensive real fast because basically you run an a* algo in every direction until a threshold is reached. Since you have a finite number of destinations, you could first use mongo to establish everything within 10 “crow-fly” miles, and then use the google distance matrix API on those possibilities to reduce the result to 10 “wolf-run” miles. Careful though, google is a nazi when it comes to rate limits, you’ll have to mitigate that by using a recursive callback in your code…
Hope I’ve made it obvious that you should just stick to a clean and easy $near in your good ol mongo. Cheers
@mattkrick after reading your reply I was able to find this link after googling about Geospatial query operator $ near. So I thought I’d share it hear to help other people who have the same problem with mine. https://github.com/n0ne/localgeo
You found my link, cool (-:
But in my case I publish all markers and make search on the client.
In your case, it might make sense to publish the markers within 30-50 miles, and the client has to make a selection within 10 miles