Having trouble connecting MongoDB with Leaflet using Node.js

474 views Asked by At

The following code works and shows my marker (var testing) on my website map, but when I switch over and try and pull the same JSON file from MongoDB I cannot get it to show up on the map. How do I call the service call from my controller?

.controller('MarkersSimpleController', function ($scope, $location, $http, Contacts1) {
    var testing = {
        "_id": {
            "$oid": "5855fa53942137001165e01c"
        },
            "marker": {
                "lat": 37.7798,
                "lng": -122.43598,
                "placename": "test",
                "message": "Drag me to add point!",
                "focus": true,
                "draggable": true,
                "description": "test",
                "url": "test",
                "entryname": "test",
                "time": "test"
            }
        };

    angular.extend($scope, {
        sanfran: {
            lat: 37.77,
            lng: -122.44,
            zoom: 12
        },
        markers: testing,
        position: {
            lat: 37.77,
            lng: -122.435
        },
        events: { // or just {} //all events
            markers:{
                enable: [ 'dragend' ]
                  //logic: 'emit'
            }
        }
    });

    $scope.$on("leafletDirectiveMarker.dragend", function(event, args){
        $scope.position.lat = args.model.lat;
        $scope.position.lng = args.model.lng;
    });
})

Here's the service function I want to call from my controller:

.service("Contacts1", function($http) {
    this.getContacts = function() {
        return $http.get("/contacts").
            then(function(response) {
                return response;
            }, function(response) {
                alert("Error finding contacts.");
            });
    }

I feel like the answer to this is simple, but I cannot figure out how to make it work. The location of the MongoDB is {url}/contacts which is in JSON format.

This is my first post.. I usually can find what I need online and feel like I have exhausted those resources. Every time I think I've connected with Mongo the point will not show up on Leaflet. Thank you so much in advance!

0

There are 0 answers