2013-11-19 18:33:19 +00:00
## GeoPoint object
The GeoPoint object represents a physical location.
Use the `GeoPoint` class.
```js
var GeoPoint = require('loopback').GeoPoint;
```
Embed a latitude / longitude point in a [Model ](#model ).
```js
var CoffeeShop = loopback.createModel('coffee-shop', {
location: 'GeoPoint'
});
```
2014-01-21 17:55:43 +00:00
You can query LoopBack models with a GeoPoint property and an attached data source using geo-spatial filters and sorting. For example, the following code finds the three nearest coffee shops.
2013-11-19 18:33:19 +00:00
```js
CoffeeShop.attachTo(oracle);
var here = new GeoPoint({lat: 10.32424, lng: 5.84978});
CoffeeShop.find({where: {location: {near: here}}, limit:3}, function(err, nearbyShops) {
console.info(nearbyShops); // [CoffeeShop, ...]
});
```
### Distance Types
**Note:** all distance methods use `miles` by default.
- `miles`
- `radians`
- `kilometers`
- `meters`
- `miles`
- `feet`
- `degrees`
2014-01-15 07:50:54 +00:00
### Methods
2013-11-19 18:33:19 +00:00
2014-01-15 07:50:54 +00:00
#### geoPoint.distanceTo(geoPoint, options)
2013-11-19 18:33:19 +00:00
Get the distance to another `GeoPoint` .
```js
var here = new GeoPoint({lat: 10, lng: 10});
var there = new GeoPoint({lat: 5, lng: 5});
console.log(here.distanceTo(there, {type: 'miles'})); // 438
```
2014-01-15 07:50:54 +00:00
#### GeoPoint.distanceBetween(a, b, options)
2013-11-19 18:33:19 +00:00
Get the distance between two points.
```js
GeoPoint.distanceBetween(here, there, {type: 'miles'}) // 438
```
2014-01-15 07:50:54 +00:00
### Properties
2013-11-19 18:33:19 +00:00
2014-01-15 07:50:54 +00:00
#### geoPoint.lat
2013-11-19 18:33:19 +00:00
The latitude point in degrees. Range: -90 to 90.
2014-01-15 07:50:54 +00:00
#### geoPoint.lng
2013-11-19 18:33:19 +00:00
The longitude point in degrees. Range: -180 to 180.