Flutter - How to save Firestore Geopoint to Json (especially Algolia) - json

I am having trouble with saving Firestore Geopoint to Json file. In my flutter app, I save Geopoint like this.
FirebaseFirestore.instance.collection('ZayyanProperties').get().then(
(value) => value.docs.forEach(
(element) {
var docRef = FirebaseFirestore.instance
.collection('ZayyanProperties')
.doc(element.id);
docRef.update({
'b18-geopoint': GeoPoint(16.00001, 96.00001)
});
The value of Geopoint is stored in Firestore database properly. Please see a screenshot of my Firestore database here
My problem is that when the Geopoint is saved to Algolia as Json, it's not saved properly. In the Json file of Algolia, Firestore Geopoint is saved as
"_geoloc": {
"lat": 16.00001,
"lng": 96.00001
},
But, I think its supposed to be saved like this??
"b18-geopoint": {
"lat": 16.00001,
"lng": 96.00001
},
Please see screenshot of Algolia Json here
So, my question is how do I properly save Geopoint in Json??
Thank you in advance.
Best

For Algolia to pick up on the geolocation data, your record should save the geolocation information into an attribute named _geoloc. This attribute can either be an object (with a lat and lng attribute), or a list of objects with lat and lng attributes. For example:
Single record:
{
"_geoloc": {
"lat": 40.639751,
"lng": -73.778925
},
...
}
Multi-record:
{
"_geoloc": [
{ "lat": 47.279430, "lng": 5.106450 },
{ "lat": 47.293228, "lng": 5.004570 },
{ "lat": 47.316669, "lng": 5.016670 }
],
...
}
You can find more information about Geolocation and Algolia here in the documentation.

Related

How to integrate the Google Places API with web application, for the locality suggestion, so that records could be filtered by location later

I am trying to make an application which will let the users search nearby vendors. For that, each vendor registration form will have a textbox where a Vendor can put his address. As I don't have the list of localities to validate against, I am trying to use Googe Places API for locality suggestion.
The locality suggestion textbox in the Vendor registration form will look like the image below:
locality suggestion textbox in the vendor registration form
The user interface to choose the location will look like the image below:
user interface to choose the location
After the locality selection, the user should see only nearby Vendors. The response of the google places API is
{
"html_attributions": [],
"results": [
{
"formatted_address": "Motera, Ahmedabad, Gujarat, India",
"geometry": {
"location": {
"lat": 23.1036054,
"lng": 72.6024044
},
"viewport": {
"northeast": {
"lat": 23.112303,
"lng": 72.611829
},
"southwest": {
"lat": 23.0824881,
"lng": 72.5931459
}
}
},
"icon": "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id": "beb375b14ad845f8a22e69c93617bee0256678b9",
"name": "Motera",
"photos": [
{
"height": 768,
"html_attributions": [
"Denny 00_"
],
"photo_reference": "CoQBdwAAADhFAFfh71z9-Ezw2FMPN-dfmbVDhp8LFJLVmipB_uiK57ZIHWX9vL6UBxotMee794LGmWy_us0RDS521rblsBJgEWL7Wzmg2_Ni9bVfvRJfE6Cb_wf9hzZqvdQUTozVP5z8FaItU-RHjv7Sz92f_ACk8_CpUsEGfeRHF13uI8j5EhDIB0RXJxrzsLVhUImoqMruGhTvq6O1_ZsOWOJslKCSVsXiU_0_gQ",
"width": 1280
}
],
"place_id": "ChIJTxIjdsODXjkRiCMOQDvxt24",
"reference": "CmRbAAAAfxr_8ylDJoydKhrJFZMQVaziF5T89c-KwrgI95qWKqlwcZddHbuAryoaYMq1Qd17v8d0l9SwM47hwuBiuzPOTAb_9tKYS_0K575oUnMIylmG48cBjzQaDzNbsNOIxPFuEhB3MNrFc3saxfKwtfVGWgbEGhTtyA6ohpXeHhwLQ42PjOiIEOkPxw",
"types": [
"sublocality_level_1",
"sublocality",
"political"
]
}
],
"status": "OK"
}
What should I store in the database from above response so that I can filter records by location? I can split the "formatted_address" key into three and store them in three separate fields in Vendor registration table. But that will be redundant. Or I can store the area, city and state in three separate table and reference the ID. But this seems to be too much work? What is the best way to handle this?
Also, does google allow storing the response data?
You need the geographic coordinates if you want to find "nearby" locations by querying your database.
Last I looked at the Places API TOU, the only data you are allowed to store persistently is the placeId.

How to put mapping in json files with Elasticsearch

i have a lot of JSON documents with this structure :
"positions": [
{
"millis": 12959023,
"lat": 49.01525113731623,
"lon": 2.4971945118159056,
"rawX": -3754,
"rawY": 605,
"rawVx": 0,
"rawVy": 0,
"speed": 9.801029291617944,
"accel": 0.09442740907572084,
"grounded": true
},
{
"millis": 12959914,
"lat": 49.01536940596998,
"lon": 2.4967825412750244,
"rawX": -3784,
"rawY": 619,
"rawVx": -15,
"rawVy": 7,
"speed": 10.841861737855924,
"accel": -0.09534648619563282,
"grounded": true
}
...
}
i'm trying to map this JSON document with Elasticsearch by introducing a geo_point field to get document like the one below :
"positions": [
{
"millis": 12959023,
"location" : {
"lat": 49.01525113731623,
"lon": 2.4971945118159056,
}
"rawX": -3754,
"rawY": 605,
"rawVx": 0,
"rawVy": 0,
"speed": 9.801029291617944,
"accel": 0.09442740907572084,
"grounded": true
},
...
}
PS : these documents are offered by an API.
Thanks
You could do something like this:
curl -XPUT 'http://localhost:9200/<indexname>/positions/_mapping' -d #yourjsonfile.json
Hope this SO helps!
If you can't modify the source, you need to pre-process your document before it gets indexed into elasticsearch.
If you are using elasticsearch < 5.0, you can use logstash and the
mutate filter.
If you are using elasticsearch >= 5.0 (my
advice), use an ingest pipeline and the rename processor.

How to prepare json data from direction service of google map to save in mongo db and plot it again on map

I am using Google Maps Directions service for routes. I want to save the response in JSON format in MongoDB for reuse to plot the route on the map again. How do I have to prepare the JSON data for routes array from the Directions service.
You can design your mongodb schema like the following. You may want to add some more details.
{
"source": "Ramlal Marg",
"destination": "Rajaram Kohli Marg",
"directions" : [
{
"type": "Left turn"
"desc" : "Take a left a turn at XYZ"
},
{
"type": "Right turn"
"desc" : "Take right turn at ABC"
},
{
"type": "Continue"
"desc" : "Continue on this road for 4 kms"
}
]
}

How can I get values from decoded file

I have a JSON file. When I encoded and decoded it, it gives me a resultset like below:
{
"_id": 519188,
"name": "Novinki",
"country": "RU",
"coord": {
"lon": 37.666668,
"lat": 55.683334
}
}
How can I get the values from that?
If you are working with javascript, you need to store the contents of json file into a javascript variable. From there you can easily access the values.
eg:- var someVariable = decodedFileContent;
var id = someVariable._id;
Hope it helps.Give more information.

How to Parse Json list in VB.NET Newtonsoft

I receive from a webservice, the following JSON:
[ {"lat": 42.41375, "user_id": 762, "user": "John", "lng": 23.02187}, {"lat": 42.46835, "user_id": 675, "user": "Mike", "lng": 23.02612}, {"lat": 42.85672, "user_id": 654, "user": "Jane", "lng": 23.01029}, {"lat": 42.46876, "user_id": 687, "user": "Luke", "lng": 23.02676} ]
I want to add this information using VB.net, row by row, to a DataGridView.
I'm new to JSON.net.
How to loop through the whole list?
How to go about parsing it?
As per as my knowledge there are multiple ways to do it, i prefer following way which is more easy ,straight and maintainable
there is JSON serializer and deserializer provided inbuilt in .net framework, requirement for that is, you have to create classes which will map to your JSON. you can have a look at or http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.deserialize.aspx
In the above case you have to create your class like below
class UserLatLang
{
public long lat { get;set;}
public long lng { get;set;}
public long user_id {get;set;}
public string user {get;set;}
}
after this you can
var serializer = new JavaScriptSerializer();
var listofUserLatLang = serializer.Deserialize<UserLatLang>(responseText);
and you will get a list of UserLatLang in listofUserLatLang
or you can also refer class from http://msdn.microsoft.com/en-us/library/bb412179.aspx
Once you get list of UserLatLang you can directly bind it to DataGrid
Hope this solves your problem
thanks,
Sandesh Daddi