raykeating/strapi-location-field-plugin

Does this work on v4.10.5?

Closed this issue · 13 comments

Fresh install, no requests are firing to google maps.

Config.json and Middleware.json are configured as your readme states. The plugin does appear in the admin but isn't making any API requests to the Places API as I'd expect.

Fresh Google Maps key, no console errors either. From what I can tell there is no request firing on input but also no JS errors. Looking for validation that this functions on the newest version of Strapi before I dig in further to what might be going wrong.

Hey @brs14ku I have not tested on the latest version but I don't imagine there would be anything breaking. You mentioned that you've got a config.js file, is this correct? If so the file with the google maps api key and any other configurations should be in a file called plugins.js in the config directory. Let me know if this fixes things

If you have set up that file properly, you may need to do npm run build to rebuild the UI. I may have forgot to add that to the readme

@brs14ku I just realized you said it was appearing in the admin panel so it's likely not related to either of the suggestion I mentioned above. I'll test it out on v4.10.5 and let you know.

Thank you! Yes, it's setup in my plugins.js and middleware.js. I've also got the API key configured in my .env .

I did add code to bring env into the plugins.js file as well. Here is my full plugins.js file currently.

    "location-field": {
        enabled: true,
        config: {
            fields: ["geometry"], // optional
            // You need to enable "Autocomplete API" and "Places API" in your Google Cloud Console
            googleMapsApiKey: env("GOOGLE_MAPS_API_KEY"),
            // See https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service#AutocompletionRequest
        },
    }
});```

FWIW I've also tried using your example file directly with hardcoding my key.

module.exports = {
    "location-field": {
        enabled: true,
        config: {
            fields: ["photo", "rating"], // optional
            // You need to enable "Autocomplete API" and "Places API" in your Google Cloud Console
            googleMapsApiKey: 'KEY',
            // See https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service#AutocompletionRequest
            autocompletionRequestOptions: {},
        },
    }
    // .. your other plugin configurations
};

I had the Places API enabled, instead of the Maps API. 🤦‍♂️

Haha it's always the little things. Glad you were able to get it working

@raykeating Well, actually, it's working but doesn't save to the content. The item doesn't even detect that it's got something to save when making changes. Ever seen that? I can make a screen recording.

Yeah a screen recording would be great, thanks. As the readme says, the plugin is still in early development so there are definitely still some issues to be worked out. If I can find the bug, I'll try to fix by the end of this week.

Yep, I understand. I think I've isolated it, actually. It DOES save it, it's just that when you refresh or visit the edit screen it doesn't mount it to the input from what was saved. I verified by looking at the API results. Is it because you're instantiating it each time with useState(null)?

Ah, got it. Yeah it could definitely be related to that, it's been a while since I've looked at that code. It's a little weird because the location data is stored as raw JSON under the hood so I had to parse and unparse it every time it loads. So it could also be related to that. I'll take a look later this week or if you think you could figure it out a PR would be much appreciated

Testing on the same version, I noticed the following issues:

  1. When specifying "geometry" only, the location is saved but is not displayed when editing
  2. If specifying other fields besides geometry, they're not saved (I guess this is known, but in case it happens to someone)
  3. Location Bias (per example) doesn't seem to work.

@brs14ku I was able to reproduce your issue, and it should be fixed now (v1.2.2). Let me know if you're still experiencing issues. @edwardbc I believe your first issue should be fixed now,

The second issue is known, but for the time being I don't have plans to support anything other than ratings, photos, and geometry. Those fields should work, although they will be empty for locations where they don't apply, for example on a residential street address. The third I have not tested recently, as the feature was contributed by @rolodato. But I will test that one at some point soon as well.