How to add _geoloc data from Android?

I need to send data to Algolia from my Android, the data sent should be in JSONObject format (import org.json.JSONObject).

the data in Algolia should be in this format

"_geoloc": {
  "lat": 40.639751,
  "lng": -73.778925

so in Android, I set the code like this

val jsonObject = JSONObject()

val locHashMap = hashMapOf(
   "lat" to coordinate.latitude,
   "lng" to coordinate.longitude



but unfortunately, I get this error:

java.lang.NoSuchMethodError: No virtual method
put(Ljava/lang/String;Ljava/util/Map;)Lorg/json/JSONObject; in class
Lorg/json/JSONObject; or its super classes (declaration of
‘org.json.JSONObject’ appears in /system/framework/core-libart.jar)

in this line of code jsonObject.put("_geoloc",locHashMap)

so what should I do to send _geoloc data to my index from my Android app ?


Thanks for contacting us. This question belongs more to StackOverflow rather than here, since this discourse is only for Algolia related problems, while this is an issue with dealing with constructing JSONObject.

I see the question has been ask already here, so let’s keep the conversation there in one place :slight_smile:

Also a note:



Thanks for the response. I think this question is related to Algolia problem. because Algolia requires JSONObject to add record to the index. and algolia also requires specific format to add _geoloc data. but when I combine it, it doesn’t work. because no one can answer there,thats why I bring it here. Hopefully Algolia team can help us. Thank you :slightly_smiling_face: