简体   繁体   中英

Meteor CityForks Demo Assistance

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM