How to load Google Maps API in MeteorJS Server?
我正在尝试在流星应用程序的服务器端加载Google Maps javascript API。我在
1 2 3 4 5 6 7 | Router.map( function () { this.route('codeEditor',{ waitOn: function(){ return [IRLibLoader.load('https://maps.googleapis.com/maps/api/js?libraries=places,geometry?key=MyKey')] } }); }); |
我创建的相关方法是:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Meteor.startup(function() { Meteor.methods({ getCoords: function(startLocation,endLocation,priceFilter) { var directionsService = new google.maps.DirectionsService(); var path = [] var request = { origin:startLocation, destination:endLocation, travelMode: google.maps.TravelMode.DRIVING }; directionsService.route(request, function(result, status) { if (status == google.maps.DirectionsStatus.OK) { path = result.routes[0].overview_path; Meteor.call('samplePath',path); } }); |
如果您有任何见解,我将不胜感激!谢谢!
您必须记住流星是基于node.js的框架。服务器端是node.js。因此,为了加载库,最好的选择是查看如何在node.js中加载库。