# How to create Location object in Groovy/Java

**URL:** <https://discuss.elastic.co/t/how-to-create-location-object-in-groovy-java/31602>\
**Category:** Elasticsearch\
**Created:** [October 5, 2015, 2:57am UTC](https://discuss.elastic.co/t/how-to-create-location-object-in-groovy-java/31602 "2015-10-05T02:57:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajeshdommati](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@rajeshdommati](https://discuss.elastic.co/u/rajeshdommati)\
**Post date:** [October 5, 2015, 2:57am UTC](https://discuss.elastic.co/t/how-to-create-location-object-in-groovy-java/31602/1 "2015-10-05T02:57:31Z")

</div>

I am getting latitude and longitude values from a rest API and i want to create a location object in groovy/java(may be using double arrays) and store it to Elasticsearch with other parameters. I know how to do this through logstash and wondering how to achieve it from groovy/java..

how to created the below object using groovy/java.  
"location": {  
"lat": "50.68262437",  
"lon": "7.5592885"  
}

Thanks in advance!!

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [October 5, 2015, 5:43am UTC](https://discuss.elastic.co/t/how-to-create-location-object-in-groovy-java/31602/2 "2015-10-05T05:43:39Z")

</div>

Just create a Groovy map. It'll be serialized to a JSON object with lat and lon properties.

```
def location = [
  lat: "50.68262437",
  lon: "7.5592885"
]

```

(Although I suspect the lat/lon values should be floating point values and not strings.)

---

<div class="post-metadata">

**Author:** ![rajeshdommati](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@rajeshdommati](https://discuss.elastic.co/u/rajeshdommati)\
**Post date:** [October 9, 2015, 5:28pm UTC](https://discuss.elastic.co/t/how-to-create-location-object-in-groovy-java/31602/3 "2015-10-09T17:28:52Z")

</div>

Thanks Mangus,

I got it, it was not as difficult as i thought.

here is my experience  
2 things to take care.

1. in My Java class I have created a GeoPoint object like this..

GeoPoint location = new GeoPoint(lat,lon)

// latitude(lat) and longitude(long) values are double values.

1. Map the location object as below in Elasticsearch  
"mappings": {  
"properties": {  
"location": {  
"type": "geo\_point"  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:45pm UTC](https://discuss.elastic.co/t/how-to-create-location-object-in-groovy-java/31602/4 "2017-07-05T23:45:36Z")

</div>


