Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apikey errors with geocode and reverseGeocode #294

Closed
TannerJuby1 opened this issue Apr 5, 2022 · 2 comments · Fixed by #295
Closed

apikey errors with geocode and reverseGeocode #294

TannerJuby1 opened this issue Apr 5, 2022 · 2 comments · Fixed by #295
Labels

Comments

@TannerJuby1
Copy link

I am trying to use this package with my Gatsby (react) project but am running into issues with using my apikey.

Due to an issue I recently opened I import this package directly into my components to try and use

import * as ELG from 'esri-leaflet-geocoder'

When I use geosearch, the api key is applied and it works as expected:

const searchControl = ELG.geosearch({
  providers: [
    ELG.arcgisOnlineProvider({
      apikey: process.env.ARCGIS_API_KEY,
    }),
  ],
}).addTo(map)

But the geocode and reverseGeocode functions do not accept the apikey I pass in and I just get an error response about token being required. I've tried the following methods to pass in the apikey:

// geosearch method
ELG.reverseGeocode({
  providers: [
    apikey: process.env.ARCGIS_API_KEY
  ]
})...

// documentation method
ELG.reverseGeocode({
  apiKey: process.env.ARCGIS_API_KEY
})...

// documentation method 2
ELG.reverseGeocode({
  apikey: process.env.ARCGIS_API_KEY
})...

and none of these work, I always get the Token Required error response.

What is the proper way to pass the token to these methods?

@gavinr
Copy link
Contributor

gavinr commented Apr 5, 2022

Hi, thank you for logging the issue. I think you can pass the apikey with .geocode() - here is sample code:

import * as esriLeafletGeocoder from "esri-leaflet-geocoder";

esriLeafletGeocoder
  .geocode({
    apikey: "...."
  })
  .text("380 New York St, Redlands, CA")
  .run(function (err, results, response) {
    if (err) {
      console.log(err);
      return;
    }
    console.log("geocode results:", results);
  });

Here is a sample showing it working: https://codepen.io/gavinr/pen/mdpXXJd?editors=0010

For .reverseGeocode() trying to follow the same pattern, I'm getting an error. I think it's an issue that needs correction in https://github.com/Esri/esri-leaflet-geocoder/blob/master/src/Tasks/ReverseGeocode.js (similar to the change in #278)

@gavinr
Copy link
Contributor

gavinr commented Apr 8, 2022

This is fixed in version 3.1.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants