gakonst

Untitled

Feb 24th, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import googlemaps
  3. from datetime import datetime
  4. from flask import Flask, jsonify, request, render_template
  5. from flask_googlemaps import GoogleMaps
  6. from flask_googlemaps import Map
  7.  
  8. app = Flask(__name__)
  9. key ="AIzaSyChUm3S41NRm2N2QAyLCUhPuydaRZg1XYo"
  10. app.config['GOOGLEMAPS_KEY'] = key
  11. GoogleMaps(app)
  12. gmaps = googlemaps.Client(key="")
  13.  
  14. SWISS_COORD = (46.83, 8.05)
  15.  
  16. # @app.route("/api/swissmap")
  17. # def mapview():
  18. # # creating a map in the view
  19. # mymap = Map(
  20. # identifier="view-side",
  21. # lat= SWISS_COORD[0],
  22. # lng=SWISS_COORD[1]
  23. # )
  24. # # render_template('example.html', mymap=mymap)
  25. # return jsonify(mymap.as_json())
  26.  
  27. @app.route('/api/keywords', methods = ['POST'])
  28. def get_maps():
  29. params = request.form # get form data
  30. keyword = params['keyword']
  31. radius = params['radius'] or 500000
  32. d = gmaps.places_autocomplete_query(keyword, location=SWISS_COORD, radius=radius)
  33. # d = gmaps.places_nearby(location=SWISS_COORD, keyword=keyword)
  34. return jsonify(d)
  35.  
  36. if __name__ == '__main__':
  37. app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment