Start a new topic
Answered

No return using location

Hello


I'm working with PHP doing RestAPI calls with CURL. It works all fine so far, just struggle with Location. I'm using it that way:


    

        //curl_setopt ($ch, CURLOPT_URL, 'https://baas.kinvey.com/appdata/kid_xxxxxxxxx/spots/?query={"$nearSphere": [-71,41], "$maxDistance":"1000" } }');
         curl_setopt ($ch, CURLOPT_URL, 'https://baas.kinvey.com/appdata/kid_xxxxxxxxx/spots/?query={"_geoloc": {"$nearSphere": [-71,41]}}');

        curl_setopt($ch, CURLOPT_HTTPGET, true);
        curl_setopt ($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Kinvey ".$authtoken, "X-Kinvey-API-Version: 3" ));

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $result = json_decode(curl_exec ($ch));
        print_r ($result);

   Whether using  $nearSphere or _geoloc both wont return anything, no error message and no empty array, just nothing. I guess I do something wrong. There are a some _geoloc coordinates in the collection 'spots' and any other query on the existing records are working (bringing something back).

Any idea what I didi wrong?


Regards



Best Answer

Tayger,


Thanks for the update. Spaces problem might be related to PHP only. I confirm that everything is working fine on Kinvey API console and SDKs. Anyway, I am glad to hear that you were able to move past the issue.


Thanks,

Pranav


Tayger,


I implemented your scenario using this link on Kinvey API console and everything is working fine. 


  • I created a collection called "location" and then added few records which contain "_geoloc" values. Following is the screenshot of "location" collection:


  • Then, on API console, I made a GET request as shown in following screenshot and successfully got 3 records:



Can you try your scenario on Kinvey API console and let me know if it works there?


Also please add "pranav@kinvey.com" as a collaborator to your app environment so that I can directly investigate the issue in your environment.


Thanks,

Pranav

Hello Pranav


Thanks for your really appreciated help and my project is heavily dependant on GPS queries. I was not aware of the API console and just tried it out: It worked out of the box! So it's weird the REST API will not return anything.


I allow me to send you an email with a out-of-the-box example that I'm using and wont return anything. It has some sensitive data in it, thats why email, otherwise I would post it here.

If you let the example run on a PHP engine you will see only a "done" after processing, no other values and no empty array.

Okay, I have found the problem: I had some spaces in my query string and Kinvey doesn't seem to like that. In the past I already found out that Kinvey also doesn't like the usage of ' instead of " inside a query.

Space problem:

...?query={"_geoloc": {"$nearSphere": [-71,41]}}'

Removing them and everything works fine! Spaces are still accepted on using API console.


This works with no spaces:

...?query={"_geoloc":{"$nearSphere":[-71,41]}}'

I never had spaces in my other queries but was not aware of that fact. 


Answer

Tayger,


Thanks for the update. Spaces problem might be related to PHP only. I confirm that everything is working fine on Kinvey API console and SDKs. Anyway, I am glad to hear that you were able to move past the issue.


Thanks,

Pranav

Login or Signup to post a comment