Reputation: 470
is there any example of how to use the google maps API using node.js to retrieve my location and compare my coordinates with locations stored in MongoDB?
Upvotes: 2
Views: 3917
Reputation: 1210
Here is the Google API documentation referring to asynchronously loading the API. Since this example is in javascript, it should work perfectly fine with any NodeJS application.
As far as comparing your coordinates with others goes, that kind of logic can be done without ever using the API since it is just a mathematical comparison.
If you want to store user.longitude
and user.latitude
variables server-side and then dynamically display them in the map created on your site, you only need to invoke map options and a marker as such:
var myLatlng = new google.maps.LatLng(user.latitude, user.longitude );
var mapOptions = {
center: myLatlng,
zoom: 8
};
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Hello World!"
});
Where your HTML would look like
<div id="map-canvas"/>
Read through the Google Maps Javascript API I have linked to. There are many different options for markers and map styles.
Upvotes: 2