Is it possible to create geospatial index not on document level but on property level in mongodb? - mongodb

I am currently working with a mongodb containing a collection of companies with the following structure:
{
"_id": "52cdef7c4bab8bd675297d8e",
"name": "Facebook",
"offices": [{
"description": "Headquarters",
"address1": "1601 Willow Road",
"address2": "",
"zip_code": "94025",
"city": "Menlo Park",
"state_code": "CA",
"country_code": "USA",
"latitude": 37.41605,
"longitude": -122.151801,
"location": {
"type": "Point",
"coordinates": [-122.151801, 37.41605]
}
}, {
"description": "Europe HQ",
"address1": "",
"address2": "",
"zip_code": "",
"city": "Dublin",
"state_code": null,
"country_code": "IRL",
"latitude": 53.344104,
"longitude": -6.267494,
"location": {
"type": "Point",
"coordinates": [-6.267494, 53.344104]
}
}, {
"description": "New York",
"address1": "340 Madison Ave",
"address2": "",
"zip_code": "10017",
"city": "New York",
"state_code": "NY",
"country_code": "USA",
"latitude": 40.7557162,
"longitude": -73.9792469,
"location": {
"type": "Point",
"coordinates": [-73.9792469, 40.7557162]
}
}]
}
As the example shows a company can have multiple offices.
What I would like to know is, if it is possible to create a geospatial index at offices level not at document (root) level? For example, the user of my application is currently in Dublin and searches within a distance of 50km, he/she will get "Facebook, Europe HQ" in his/her results and not just "Facebook"?
If yes, how can I achieve that, if not what could I do then?

Related

Using JSON on Grafana's Worldmap Panel

The Worldmap Panel plugin for Grafana's documentation specifies the necessary input data like the following:
[
{
"key": "SE",
"latitude": 60.128161,
"longitude": 18.643501,
"name": "Sweden"
},
{
"key": "US",
"latitude": 37.09024,
"longitude": -95.712891,
"name": "United States"
}
]
Source: https://grafana.com/grafana/plugins/grafana-worldmap-panel/
I've tried inputting data by using a Zabbix data source and a JSON/JSONP endpoint under the panel's "Map Data Options".
JSON Endpoint Response Data:
[
{
"name": "United States",
"key": "US",
"longitude": -85.997,
"latitude": 37.7529
},
{
"name": "Australia",
"key": "AU",
"longitude": 151.2006,
"latitude": -33.8715
},
{
"name": "United States",
"key": "US",
"longitude": -122.0438,
"latitude": 37.3177
},
{
"name": "United Kingdom",
"key": "GB",
"longitude": -1.6451,
"latitude": 54.9749
},
{
"name": "Portugal",
"key": "PT",
"longitude": -8.6793,
"latitude": 41.1691
},
{
"name": "United States",
"key": "US",
"longitude": -96.6146,
"latitude": 33.6416
},
{
"name": "Egypt",
"key": "EG",
"longitude": 29.7432,
"latitude": 30.9977
},
{
"name": "United Kingdom",
"key": "GB",
"longitude": -0.2972,
"latitude": 51.5571
},
{
"name": "United States",
"key": "US",
"longitude": -97.0951,
"latitude": 32.8285
}
]
Zabbix Data Source:
[{"name":"Trinidad and Tobago","key":"TT","longitude":-61.4692,"latitude":10.2843},{"name":"Australia","key":"AU","longitude":151.2006,"latitude":-33.8715},{"name":"United Kingdom","key":"GB","longitude":-1.6451,"latitude":54.9749},{"name":"United States","key":"US","longitude":-96.6146,"latitude":33.6416},{"name":"United Kingdom","key":"GB","longitude":-0.2972,"latitude":51.5571},{"name":"Egypt","key":"EG","longitude":29.7432,"latitude":30.9977},{"name":"United States","key":"US","longitude":-97.0951,"latitude":32.8285}]
Both options show nothing on the map. I've tried various options and nothing seems to work.
Am I misunderstanding how the map should consume this data?
If so, how would I proceed with transforming the data from their respective source?
My Worldmap Panel Setup

how to Calculate distance base on lat long mongodb

{
"_id": ObjectID("5e576bf5d72a185fcf11e03f"),
"location": {
"latitude": 27.6648,
"longitude": 81.5158,
"city": "Florida",
"state": "Florida",
"country": "United State"
},
"description": "This is for test",
"distance" : "100" //Miles
}
How can get the record that calculate the minium distance between coordinates tried difference way didn't get success

Which fields are available for the &fields parameter in the Graph API /search endpoint?

I'm working with the Facebook Graph API and I was wondering which fields are available for the &fields parameter and also where do I find any documentation about those fields.
I could only find the Search types for the &type parameter in the documentation for example the page Search type let's you search for a page if you provide a name to be queried.
Example request
search?q=Facebook&type=page
Example response
{
"data": [
{
"category": "Computers/technology",
"name": "Facebook Engineering",
"id": "9445547199"
},
{
"category": "Product/service",
"name": "Facebook",
"id": "103274306376166"
},
{
"category": "Product/service",
"name": "Facebook Developers",
"id": "19292868552"
},
{
"category": "Media/news/publishing",
"name": "Facebook Stories",
"id": "114770288670819"
}
]
}
If I now need some specified fields from this collection I know from a previous experience that I could use the &fields parameter to extract them or filter them out.
Example request
search?q=Facebook&type=page&fields=name, likes, location
Example response
{
"data": [
{
"name": "Facebook NY",
"likes": 71564,
"location": {
"street": "770 Broadway",
"city": "New York",
"state": "NY",
"country": "United States",
"zip": "10003",
"latitude": 40.730901749524,
"longitude": -73.991377364328
},
"id": "28864583650"
},
{
"name": "Facebook London",
"likes": 56441,
"location": {
"street": "10 Brock Street",
"city": "London",
"state": "",
"country": "United Kingdom",
"zip": "NW1 3FG",
"latitude": 51.5258476,
"longitude": -0.1394228
},
"id": "265781023507354"
},
{
"name": "Facebook Paris",
"likes": 29740,
"location": {
"street": "",
"city": "Paris",
"state": "",
"country": "France",
"zip": "75017",
"latitude": 48.883443087419,
"longitude": 2.3023060392957
},
"id": "147424071942327"
}
]
}
I used the Graph API Explorer to do this
TLDR; is there a list or documentation available for all the options/specific fields in the &fields parameter?
Although there is no complete documentation, for any element you can query
{id}?metadata=1
this will give you a full list of fields and edges that are available for that object type (as well as its type at the very bottom)
sample call: https://graph.facebook.com/v2.8/me?metadata=1
There is no exact documentation on the search fields endpoint.
An educated guess would be that based on the type you can inspect the fields of that page.
Example, for type=page the fields available will be listed at https://developers.facebook.com/docs/graph-api/reference/v2.2/page

iphone: parsing a string

Hey I have a response string in this format
ok my original resonse string is like this
{
"data": [
{
"name": "Santa Fe Plaza",
"category": "Landmark",
"location": {
"city": "Santa Fe",
"state": "NM",
"country": "United States",
"latitude": 35.687071155202,
"longitude": -105.93767717603
},
"id": "108196762542063"
},
{
"name": "Museum of Contemporary Native Arts",
"category": "Museum/art gallery",
"location": {
"street": "108 Cathedral Place",
"city": "Santa Fe",
"state": "NM",
"country": "United States",
"zip": "87501",
"latitude": 35.686915835451,
"longitude": -105.93725120129
},
"id": "106209180361"
}
]
}
I have to extract all the names from there Please enlighten me how to achieve this
JSON parser is throwing error all the time
Thanx in advance
Start by downloading the JSON framework
And a Good Tutorial to Start learning: JSON Framework for iPhone
Also see: How to parse JSON files on iPhone in Objective-C into NSArray and NSDictionary

How to find location

I am new developer on iPhone. My problem is that I'm finding latitude and longitude using CLLocation. I want find the address using these latitude and longitude.
Please help me.
What you are describing is called reverse geocoding. MapKit has a class called MKReverseGeocoder that does this for you.
You create an instance, initialize it with your coordinates, start it and then wait for a delegate callback which will pass you the address. You can find all the details in the docs.
Hope that helps.
here is straight solution
make a call to
http://api.fwix.com/general/getgeo.json?lat=*****&lon=*****
like
http://api.fwix.com/general/getgeo.json?lat=37.75&lon=-122.68
it will return a json string
{
"error": 0,
"result": {
"id": "1",
"pretty": "SF Bay Area Metro",
"lat": "37.7145",
"lon": "-122.25",
"short": "sfbay",
"country": {
"placeid": "225",
"pretty": "United States of America",
"lat": "37.0902",
"lon": "-95.7129",
"short": null,
"abbr": "US",
"type": "country",
"item_type": "places",
"radius": null
},
"state": "CA",
"url": "san+francisco",
"provinceid": "273",
"countryid": "225",
"province": {
"placeid": "273",
"pretty": "California",
"abbr": "CA",
"lat": "36.7783",
"lon": "-119.418",
"countryid": "225",
"short": "california",
"title": "California",
"type": "province",
"item_type": "places",
"radius": 800
}
}
}
You have to parse this json and get
the required data from it.