perliedman / leaflet-control-geocoder

A simple geocoder form to locate places. Easily extended to multiple data providers.
http://www.liedman.net/leaflet-control-geocoder/
BSD 2-Clause "Simplified" License
560 stars 220 forks source link

I can't pass google api key #334

Closed andrecuellar closed 2 years ago

andrecuellar commented 2 years ago

Hi, I am trying to pass my API key from Google Geocoder

        let googleGeoCoderProvider = L.Control.Geocoder.google('MYGOOGLEAPIKEY');

        L.Control.geocoder({
            geocoder: googleGeoCoderProvider,
        }).addTo(map);

but the results in the console are https://maps.googleapis.com/maps/api/geocode/json?key=undefined&address=trompillo

is processing API key as undefined, the same problem with L.Control.Geocoder.Google('MYGOOGLEAPIKEY');

for it to work, I had to open the plugin code and directly replace key: with my APIKEY

var Google = /*#__PURE__*/function () {
    function Google(options) {
      this.options = {
        serviceUrl: 'https://maps.googleapis.com/maps/api/geocode/json'
      };
      L__namespace.Util.setOptions(this, options);
    }

    var _proto = Google.prototype;

    _proto.geocode = function geocode(query, cb, context) {
      var params = geocodingParams(this.options, {
        key: 'MYAPIKEY',
        address: query
      });

how can I pass the API key from my JS code?

simon04 commented 2 years ago

Please see https://www.liedman.net/leaflet-control-geocoder/docs/classes/google.html#constructor