0

With reference to Josh Owens' Cityforks demo, I've gotten the get current location to work correctly and my app is not crashing but when I check Robomongo, the places collection is not populating the database.

I've copied the code exactly though:

Places = new Mongo.Collection('places');

Meteor.methods({
    'fetchNearbyLocations': function(coords) {
         if (Meteor.isServer) {
             results = HTTP.get("https://maps.googleapis.com/maps/api/place/nearbysearch/json? location=" + coords.latitude + "," + coords.longitude +  "&radius=500&types=food&key=AIzaSyCtfoCAldCEf8hXUlkVUd4UljqKR6W_aF4")
             console.log(results)
             _(results.data.results).each(function(loc) {
                 _.extend(loc, {loc: {type: "Point", coordinates:   [loc.geometry.location.lng, loc.geometry.location.lat]}})
                 Places.upsert({id: loc.id}, {$set: loc})
             });
         }
     }
 });

Regarding the API key that I would of course change, is it the Key for server apps (with IP locking) or the Key for browser apps (with referers) that one should use?

I did remove autopublish, not sure if that makes a difference?

Also, would one have to add something like the below to a JS file somewhere within the project?

<script type="text/javascript" src="http://maps.google.com/maps/api/js?           sensor=false">   </script>

Any assistance would be greatly appreciated.

Brian Shamblen
  • 4,653
  • 1
  • 23
  • 37
Jaysonvdw
  • 51
  • 5

1 Answers1

0

About the API Key

It's the key for browser apps. https://developers.google.com/maps/documentation/javascript/tutorial#api_key

Finding the collection in Robomongo

The collection should show up in Robomongo if you simply follow Josh's code. Are you running on localhost? If you're on port 3000 for example, your database is on port 3001, and you have to enter this into your new Robomongo connection.

Then look in your New Connection>Meteor>Collections> and you should see places. Click on it and you should see 50 entries for db.places.find (or however many places you've opted to return in your code).

To check otherwise, just go into your browser's console (option+command+j in Chrome on OS X) and type Places.find().fetch() and you should get 50 objects returned.

Or in terminal, in your app's directory type meteor mongo to enter the mongo shell, and there type db.places.find().pretty() to see if your collection is properly populated.

If these work, then I think it means that you just aren't looking at Robomongo correctly, but you'll see that it's really easy.

Adding a script

The http call to google maps is already in the fetchNearbyLocations method, so that's enough as far as I understand. The sensor parameter is no longer required by Google Maps. source

Hope that helps!

Community
  • 1
  • 1
Mallory-Erik
  • 1,750
  • 1
  • 19
  • 24
  • Hi, I did an exact git clone and used the advised key and it is now working on my side now. Thank you for the assistance. If I wanted to return, say, movie_theaters within a certain range or bars within another, for example, how would I create other collections that would populate the database in the same way? I don't need the results to show up on the map necessarily. Thank you. – Jaysonvdw May 15 '15 at 13:49
  • Hi there, well, the query goes in the api key. Look at the second half of your key and you'll see it says "food": "&radius=500&types=food&key=AIzaSyCtfoCAldCEf8hXUlkVUd4UljqKR6W_aF4" – Mallory-Erik May 16 '15 at 23:22
  • Thanks again for the feedback. I now keep getting this error though: statusCode: 200, "This API project is not authorised to use this API. Please ensure that this API is activated in the API's Console – Jaysonvdw May 18 '15 at 04:38