Giter VIP home page Giter VIP logo

google-maps-api's Introduction

#google-maps-api Load a Google Maps API Object asynchronously. This module will return a Promise. Which will on resolved will return the "google.maps" object.

Or if you prefer you can simply use the callback instead.

This module also includes utility modules to be able to use parts of the maps api quickly:

geocode

Example

using via promise

var mapsapi = require( 'google-maps-api' )( 'your api key' );

mapsapi().then( function( maps ) {

  //use the google.maps object as you please
});

using via callback

require( 'google-maps-api' )( 'your api key', function( maps ) {

  //use the google.maps object as you please
})

including external google maps libraries

require( 'google-maps-api' )( 'your api key', ['places'], function( maps ) {

  //the google.maps object will now have the places api (google.maps.places)
})

API

  • apikey String | Object - Your Google Maps API Key or an object of the form { client: 'APIClientName', channel: 'APIClientChannel' }
  • [libraries] Array - Optional array of libraries to load such as [ 'places' ]
  • [onComplete] function - Optional callback which will return the google.maps object

Returns: Promise - When this promise resolves it will return the google.maps object

google-maps-api's People

Contributors

futurekode avatar mattdesl avatar mikkoh avatar njam3 avatar notheotherben 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

google-maps-api's Issues

Server Side

Hello, I'm trying to use google-maps-api on the server-side, is It possible? If it is, how I do this correctly?

I followed the examples, but I'm getting this error:

ReferenceError: document is not defined
parse-server-test-1     at /home/parse-test/node_modules/google-maps-api/node_modules/scriptjs/dist/script.js:12:13

bump to 3.21

v3 - 3.20 have been retired by Google. Bump to 3.21.

screen shot 2016-02-17 at 10 15 25

Aurelia-CLI

I'm trying to migrate from JSPM to Aurelia CLI.
While working with JSPM all was good and working, but after the migration I cannot figure out how to set in the right way the reference.
Is there any version compatible with Aurelia-CLI? Or any suggestions to get it working back again?

Document use of key parameter to allow choosing language served by the Google Maps API script

The Google Maps API supports specifying a language for use with the API. This is great to prevent having multiple languages around a website, which happens when using a different language on the browser than the used on the website.

Problem

This library currently does not specifically support specifying parameters for the loaded script, which is used to specify a language for the script.

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap&language=ja&region=JP"></script>

I have no concrete proposition on how it should be presented in this library's API, but it looks like this would be a breaking change, unless the second parameter is type checked and an Object is used with a libraries: [] key for libraries and other keys passed (sanitized?) to the URL.

Solution

The key parameter also allows setting parameters, used mainly to allow use of enterprise accounts (See #3). Luckily, this allows us to use these keys to set a language, or any other parameters accepted on the script tag.

Instead of :

const mapsapi = require( 'google-maps-api' )( 'your api key', ... );

Use:

const mapsapi = require( 'google-maps-api' )( {key: 'your api key', language: "xx"}, ... );

Old Workaround

I'm using the fact that the libraries array is unsanitized to append my own language.

https://github.com/Jam3/google-maps-api/blob/master/index.js#L103

mapsapiLoader(GMAPS_API_KEY, ["places","&language=xx"]);

Though, this is as wrong as it can be! I would hazard, that while it is a bad idea, it would be better to keep this behaviour until an API breaking version is released.

How to load libraries with Promise example

Hi, I have an Aurelia app where I'm using the promise example from your docs to load the google-maps-api. I'm trying to figure out how to load the optional libraries, since there wasn't an example using promises. Here is what I tried

// class decorator:
@inject(mapsapi('AIzaSyDGLuTAy_zb724BrnVNWfbmUwmqC0A7rNo', ['places']))
// constructor
constructor(mapsapi) {
    let vm = this;
    let maps = mapsapi.then( function(maps) {
            vm.maps = maps;
            vm.geocoder = new google.maps.Geocoder();
        });
    }

It works, except that it doesn't pull in the places libary. google.maps.places => undefined.

can't load google-maps-api

i have just follow the example section
var mapsapi = require( 'google-maps-api' )( 'api key' );

mapsapi().then( function( maps ) {

//use the google.maps object as you please
});

then

npm install google-maps-api
I got following error

E:\temp\map1\node_modules\google-maps-api\node_modules\scriptjs\dist\script.js:1
2
var doc = document
^

ReferenceError: document is not defined
at E:\temp\map1\node_modules\google-maps-api\node_modules\scriptjs\dist\scri
pt.js:12:13
at doc (E:\temp\map1\node_modules\google-maps-api\node_modules\scriptjs\dist
\script.js:8:72)
at Object. (E:\temp\map1\node_modules\google-maps-api\node_module
s\scriptjs\dist\script.js:11:3)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object. (E:\temp\map1\node_modules\google-maps-api\index.js:3:
14)

can you please help ?

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.