Geolocation via an API

Oops - seems we missed to add those events :slight_smile: will add them in the next update.

But anyway as the data comes in your page will be refreshing directly with the data bindings being refreshed. But it is good to be able to handle loading failures

1 Like

Wow, you mean for a change this was not me, yeah…

a general example with headers / query for these API’s would be nice

1 Like

In my particular case i am using this as my api
<dmx-api-datasource id="api1" is="dmx-fetch" url="http://www.geoplugin.net/json.gp" dmx-param:base_currency="'GBP'"></dmx-api-datasource>

The service has a second service that can also be used
<dmx-api-datasource id="api2" is="dmx-fetch" url="http://www.geoplugin.net/extras/nearby.gp" dmx-param:radius="50" dmx-param:format="'json'" dmx-param:limit="1" dmx-param:lat="-29.8255400" dmx-param:long="30.9370000"></dmx-api-datasource>

This second service can get the lat and long from the first but I would need to make sure the first call has finished loading before i can run the second, although i have made it work by just manually inputting the lat and long for test purposes.

Right now my bigger issue though is actually this

I added this to my .htaccess file in hopes but it does not seem to work as expected

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>
1 Like

@psweb okay I got it now! Great! Could be added to API Howto

Once i get this working i will make a small tutorial for anyone else as to what i managed to get working.

1 Like

add "Moesif Origin & CORS changer " extension to your chrome
then TURN ON it and success :slight_smile:

You mean just for testing purposes, i assume a chrome extension will not work if i am showing the output to multiple users? Maybe I am just very confused though.

are you using nginx on server side

Nope, I am on a CentOS linux hosting with this particular server.

Please check @psweb
https://enable-cors.org/server_apache.html
https://enable-cors.org/server.html
you can test it
https://www.test-cors.org/

1 Like

I am clearly confused by this CORS stuff, so quick question is the CORS error something on my webserver or something on the remote webserver protecting itself.

I understand your question I wish I can tell you with my bad english :)) lets try :slight_smile:

for example;
if you are creating mobile app (hybrid) you have to upload all php files to your remote host and you can use client side javascript … CORS will check which domain request When click to any submit button on your mobile side …
it is protect your request

Perfect, that made 100% sense, thank you for that.

1 Like

CORS allows web scripts to interact more openly with content outside of the original domain, leading to better integration between web services

2 Likes

sorry for my bad english :)))

1 Like

Well I have tried everything i can think of on my side to connect to their secondary API service and can not get around that error.
What i do find strange and what leads me to believe that this is not on my side but the API developers side possibly is this.

This is the working one, note in the header how there is an entry for access-control-allow-origin

While on the second service the headers have no mention of this

And I get this error message
Access to XMLHttpRequest at 'http://www.geoplugin.net/extras/nearby.gp?format=json' from origin 'http://africacollectionbs4.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Am I correct that this could be something on the API Providers side and not my side possibly.

You can’t access that service with XMLHttpRequest, they didn’t add the Control-Allow-Origin header. It is not you that has to add the header, the service has to add it. You could try to contact them about that.

An other solution is wait for us to finish the Server Connect version and connect with that, on the server side you don’t have the problem with CORS.

3 Likes

Thanks so much for confirmation @Patrick, i contacted them and they added something and now it is all working, so happy days.

Thanks again to all that tried to help with this one.

1 Like

Seems they added the required CORS header, I think a lot of people will be happy.

2 Likes