Git Product home page Git Product logo

google_maps's Introduction

Google Maps Open in Gitpod

Elixir wrapper around Google Maps APIs

Actions Status Build Status Hex Version License

Services

  • Directions - Directions between multiple locations.
  • Distance Matrix - Travel time and distance for multiple destinations. (contributed by @bnns)
  • Elevation - Elevation data for any point in the world.
  • Geocoding - Converts between addresses and geographic coordinates.
  • Place Add - Allows you to supplement the data in Google's Places database with data from your application.
  • Place Autocomplete - can be used to automatically fill in the name and/or address of a place as you type.
  • Place Details - Returns more detailed information about a specific Place, including user reviews.
  • Place Photo - Gives you access to the millions of Place related photos stored in Google's Place database (contributed by @gVirtu)
  • Place Nearby Search - Returns a list of places within a specified area based on a user's location or search string. (contributed by @distortia)
  • Query Autocomplete - can be used to provide a query prediction service for text-based geographic searches, by returning suggested queries as you type.
  • Timezone - Time zone data for anywhere in the world. (contributed by @uesteibar)

Methods

  • directions/3
  • distance/3
  • elevation/2
  • geocode/2
  • place_autocomplete/2
  • place_query/2
  • place_nearby/3
  • place_details/2
  • place_photo/4
  • timezone/2
  • get/2

Installation

If available in Hex, the package can be installed as:

  1. Add google_maps to your list of dependencies in mix.exs:
def deps do
  [{:google_maps, "~> 0.11"}]
end
  1. Ensure google_maps is started before your application:
def application do
  [applications: [:google_maps]]
end
  1. In your application's config/config.exs, add:
config :google_maps,
  api_key: "YOUR API KEY HERE"

Or you can use GOOGLE_MAPS_API_KEY system environment variable when running in iex.

If separate API keys are needed per request, they can be set through key option, i.e.:

GoogleMaps.directions("Toronto", "Montreal", key: API_KEY_1)

Development

You'll need a Google API key with all relevant APIs (see above) enabled. Add your key to the environment as specified above.

Then run tests:

mix deps.get test

mix test

google_maps's People

Contributors

bnns avatar caldwellysr avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar distortia avatar erneestoc avatar gvirtu avatar jowi-dev avatar kelostrada avatar leepage87 avatar migbot avatar mishaconway avatar rsierra avatar sntran avatar uesteibar avatar wisq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

google_maps's Issues

Library config

Hi,

What do you think about adding a param with an API key to each public function?

I mean, e.g. geocode(input, options \\ [], api_key).

That way, we can have a more control over API keys used in the application. If someone doesn't provide api_key, an application can fall back to config:
@api_key Application.get_env(:google_maps, :api_key) || System.get_env("GOOGLE_MAPS_API_KEY") as it is set in the GoogleMaps.Request

unable to encode value

Hello, what I do wrong?
My code:

GoogleMaps.place_nearby({-33.8670522,151.1957362}, 1500, [type: "restaurant", keyword: "cruise"])

Responce:

Request: GET /api/v1/quests
** (exit) an exception was raised:
    ** (Poison.EncodeError) unable to encode value: {:ok, %{"html_attributions" => [], "results" => [%{"geometry" => %{"location" => %{"lat" => -33.8585858, "lng" => 151.2100415}, "viewport" => %{"northeast" => %{"lat" => -33.85723597010728, "lng" => 151.2113913298927}, "southwest" => %{"lat" => -33.85993562989272, "lng" => 151.2086916701072}}}, "icon" => "https://maps.gstatic.com/mapfiles/place_api/icons/bar-71.png", "id" => "8e980ad0c819c33cdb1cea31e72d654ca61a7065", "name" => "Cruise Bar, Restaurant & Events", "opening_hours" => %{"open_now" => false, "weekday_text" => []}, "photos" => [%{"height" => 1134, "html_attributions" => ["<a href=\"https://maps.google.com/maps/contrib/112582655193348962755/photos\">Cruise Bar, Restaurant &amp; Events</a>"], "photo_reference" => "CmRaAAAA4l9jBRk9emxSsOW4l3lYkTke9HI6VeUKPmxoiNxSIfG-_P640Re-A7y2pOvnQCcEjv1SJBFlC0O9i26sGLkAddbaVX_-tu-gUb_Z6ImE7n2ei3_SNfV90EA-fwK3zBdHEhBmBIKr-bPIPRZzWF5ZdJHvGhQ3hrrV-PJWvYG0xSnW0jrIbFO-rg", "width" => 2048}], "place_id" => "ChIJi6C1MxquEmsR9-c-3O48ykI", "rating" => 3.9, "reference" => "CmRbAAAADy3xxDdOwz6rpzZoUYpIicynJ2cSyCpnc_Y0eTQhe4zkjVHpNkCgONx8fRXcmhGwqQUwPM1a6FxxtdU2OH-17DekWQ4ne36EBROj0sG1Y_jek_7H-ssk2ELMiVaXeNaBEhDYHn9TgDMC3fSkmRhZjIQzGhSPZO9YfueOnRRKZySzctbsOHGOYg", "scope" => "GOOGLE", "types" => ["bar", "restaurant", "food", "point_of_interest", "establishment"], "vicinity" => "Circular Quay W, Sydney"}, %{"geometry" => %{"location" => %{"lat" => -33.8609472, "lng" => 151.209872}, "viewport" => %{"northeast" => %{"lat" => -33.85959737010728, "lng" => 151.2112218298927}, "southwest" => %{"lat" => -33.86229702989272, "lng" => 151.2085221701072}}}, "icon" => "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png", "id" => "9ea7c77cb181b1f33d19c9d76121fcc6d5246ad8", "name" => "Australian Cruise Group Circular Quay", "opening_hours" => %{"open_now" => false, "weekday_text" => []}, "photos" => [%{"height" => 1152, "html_attributions" => ["<a href=\"https://maps.google.com/maps/contrib/112378780393544273770/photos\">Australian Cruise Group Circular Quay</a>"], "photo_reference" => "CmRaAAAAwQpJPctoqIeabeo5G2qPhwKlDp4j7ZL5DmX_4OLmYEj9Y0lm-rvvMDP1jmzRqBQkkOIO497YDbRf0dWzFSuJ177CerSayTHmYXMEXUbgSSUosa7oWyFE_loZVWMYE-w7EhBDQxxKKneZyRDUUWFovTucGhT10-3ZAdCb0xrxhJeYhnvxbkZMZw", "width" => 2048}], "place_id" => "ChIJpU8KgUKuEmsRKErVGEaa11w", "rating" => 4, "reference" => "CmRbAAAA2-UPwaNRhrrS0UBvGHylcicfYKfbopt6M4Rt9QIKLAWzlwxyINNqFNbEPqBcmGY6GE4G4V13b4R7Y9e4llT_XrB9wjxAuINn9yxT2biJmqGfCtz6JrUdtWJAYC6AKxEgEhDwhBHJQ1uNz91G2RVVlYvBGhT0pQ3kY14da4VDXI5NKJs1aRWI_w", "scope" => "GOOGLE", "types" => ["travel_agency", "restaurant", "food", "point_of_interest", "establishment"], "vicinity" => "6 Cirular Quay, Sydney"}, %{"geometry" => %{"location" => %{"lat" => -33.867591, "lng" => 151.201196}, "viewport" => %{"northeast" => %{"lat" => -33.86624117010727, "lng" => 151.2025458298927}, "southwest" => %{"lat" => -33.86894082989271, "lng" => 151.1998461701072}}}, "icon" => "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png", "id" => "a97f9fb468bcd26b68a23072a55af82d4b325e0d", "name" => "Australian Cruise Group", "opening_hours" => %{"open_now" => false, "weekday_text" => []}, "photos" => [%{"height" => 417, "html_attributions" => ["<a href=\"https://maps.google.com/maps/contrib/110751364053842618118/photos\">Australian Cruise Group</a>"], "photo_reference" => "CmRaAAAA3Dg56GKTUs3Qvkmu2EC7oO9PTlKgqVLbYG3je3oQ8pvw9x5qY_z6HI2n27M8eAVci0m5hG1LqNJ37DdENrVdWaK_lTUjvEgy7pmQK1ARYmALlrkp0Ko0ldLNztku-61XEhA9VcDnGfXpczFjjZgSoS9cGhQHAjOtRmh5p75B6n1E_G14G7uXww", "width" => 1334}], "place_id" => "ChIJrTLr-GyuEmsRBfy61i59si0", "rating" => 4.6, "reference" => "CmRbAAAAvYUfN9bbg0Jz0YrGqLyUZzBvxNjhMw2SadED54H6fZaJPoC4-SCE66lj9ZuHgZD8N8706v3RROd9GGhlCGuiSAVR0QpJ8Jv3yLp-RleaYe122Wsp8e7cCALFqZCvfLgqEhA6CjROUzV1TN6mYx4JiZ9KGhToLBGZc2j_Db3AT33GeBFaPeY4dA", "scope" => "GOOGLE", "types" => ["travel_agency", "restaurant", "food", "point_of_interest", "establishment"], "vicinity" => "King Street, Wharf 5, 32 The Promenade, Sydney"}, %{"geometry" => %{"location" => %{"lat" => -33.8686058, "lng" => 151.2018206}, "viewport" => %{"northeast" => %{"lat" => -33.86725597010728, "lng" => 151.2031704298927}, "southwest" => %{"lat" => -33.86995562989272, "lng" => 151.2004707701072}}}, "icon" => "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png", "id" => "21a0b251c9b8392186142c798263e289fe45b4aa", "name" => "Rhythmboat Cruises", "opening_hours" => %{"open_now" => false, "weekday_text" => []}, "photos" => [%{"height" => 480, "html_attributions" => ["<a href=\"https://maps.google.com/maps/contrib/104066891898402903288/photos\">Rhythmboat Cruises</a>"], "photo_reference" => "CmRaAAAAk9ikZPlpLrWw9l4GliTe6-SvuFsVfa4ChVTPT0co22xI3hI8-Yy2yNPbr8DIWPLAErS7cBZcB4sIWuxuMS6sur2QhhCSENJwsmkvPOZ63tfYBhgsHlo_u2t5fpB1urqREhDGI9UUMEMlhNRXhr2h1nOtGhTcjZE8EcWuJU-hT_nLvyzOL0RUcA", "width" => 640}], "place_id" => "ChIJyWEHuEmuEmsRm9hTkapTCrk", "rating" => 4.1, "reference" => "CmRbAAAA-AkqgIGx4sHJUiByQsRnbBARuz1IWgBkEDcID0IHPABO4mASnSFLN3iyS5e5BO-HX0TyVXCDUiq0zIyeqTlKVRZfsYHTnWJepwTlmOPv59BIXK_HKgvpXJ2svpfFNx7WEhBTo4tbuul1MpimRv18-kHVGhSJFR9LI4QY4hpo34qTB58HU7YlsA", "scope" => "GOOGLE", "types" => ["travel_agency", "restaurant", "food", "point_of_interest", "establishment"], "vicinity" => "King Street Wharf, King St, Sydney"}, %{"geometry" => %{"location" => %{"lat" => -33.867591, "lng" => 151.201196}, "viewport" => %{"northeast" => %{"lat" => -33.86624117010727, "lng" => 151.2025458298927}, "southwest" => %{"lat" => -33.86894082989271, "lng" => 151.1998461701072}}}, "icon" => "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png", "id" => "b0277cade7696e575824681aba949d68814f9efe", "name" => "Sydney New Year's Eve Cruises", "opening_hours" => %{"open_now" => false, "weekday_text" => []}, "photos" => [%{"height" => 1152, "html_attributions" => ["<a href=\"https://maps.google.com/maps/contrib/107666140764925298472/photos\">Sydney New Year&#39;s Eve Cruises</a>"], "photo_reference" => "CmRaAAAAShcNXFGgx53iE7Zu8zA3mwmCpWdkJ1VkW9xHrOOk-gf48moF-RCCeSqYcj04IRP4M39vHK2ynFz_Kl53zbM9HOpLIPuCEDV2SfEQh6HFfQirWbA9ePeAG8bKpKfacF7FEhBNajlJExQ7VrjcIa2GZbKRGhQws--Qg_8GC88ioD-_CljA9mGuug", "width" => 2048}], "place_id" => "ChIJ__8_hziuEmsR27ucFXECfOg", "rating" => 5, "reference" => "CmRbAAAAInP61yzkPKFexblKZpooyD3jEgVggBYHAd_NHzbk2N7J0gaxV9S9MxfSk3aFjZZQuxfXWlqlwQbzS--FL10o3gnjwdXJCqapocnGHxbNbDU14W2_HTIDq2wfOzgmsyV6EhBxGE_O4GaAVQnqBTGpFCEEGhSIK_uTKdtNLfAf5TZ99sjW6tvEkw", "scope" => "GOOGLE", "types" => ["travel_agency", "restaurant", "food", "point_of_interest", "establishment"], "vicinity" => "32 The Promenade, King Street Wharf 5, Sydney"}], "status" => "OK"}}
        (poison) lib/poison/encoder.ex:383: Poison.Encoder.Any.encode/2
        (poison) lib/poison.ex:41: Poison.encode!/2
        (phoenix) lib/phoenix/controller.ex:284: Phoenix.Controller.json/2
        lib/hero_web/controllers/api/quest_controller.ex:1: HeroWeb.QuestController.action/2
        lib/hero_web/controllers/api/quest_controller.ex:1: HeroWeb.QuestController.phoenix_controller_pipeline/2
        (hero) lib/hero_web/endpoint.ex:1: HeroWeb.Endpoint.instrument/4
        (phoenix) lib/phoenix/router.ex:278: Phoenix.Router.__call__/1
        (hero) lib/hero_web/endpoint.ex:1: HeroWeb.Endpoint.plug_builder_call/2
        (hero) lib/plug/debugger.ex:102: HeroWeb.Endpoint."call (overridable 3)"/2
        (hero) lib/hero_web/endpoint.ex:1: HeroWeb.Endpoint.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:16: Plug.Adapters.Cowboy.Handler.upgrade/4
        (cowboy) /home/ikethavel/ElixirProjects/hero/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

(UndefinedFunctionError) function nil.get/3 is undefined

When I try to execute:

iex(2)> GoogleMaps.place_nearby("55.780806,49.212249", 500)
Break reached: GoogleMaps.get/2 (deps/google_maps/lib/google_maps.ex:1669)

 1667:   @spec get(String.t, options()) :: Response.t()
 1668:   def get(endpoint, params) do
 1669:     require IEx; IEx.pry
 1670:     Request.get(endpoint, params)
 1671:     |> Response.wrap

pry(1)> {:ok, res} = Request.get(endpoint, params)
** (UndefinedFunctionError) function nil.get/3 is undefined
    nil.get("https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=<key>&location=55.780806%2C49.212249&radius=500", [], [])

This happens because I haven't configured requester in my config.exs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.