Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/io-sgr/geometry-common
https://github.com/io-sgr/geometry-common
gcj gcj-02 gcj02 geometry java maven wgs wgs-84 wgs84
Last synced: about 6 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/io-sgr/geometry-common
- Owner: io-sgr
- License: apache-2.0
- Created: 2017-04-25T15:09:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-02T03:03:01.000Z (over 5 years ago)
- Last Synced: 2024-07-30T18:39:42.260Z (4 months ago)
- Topics: gcj, gcj-02, gcj02, geometry, java, maven, wgs, wgs-84, wgs84
- Language: Java
- Size: 142 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Geometry Utilities
[![Build Status](https://travis-ci.org/io-sgr/geometry-common.svg?branch=master)](https://travis-ci.org/io-sgr/geometry-common) [![codecov](https://codecov.io/gh/io-sgr/geometry-common/branch/master/graph/badge.svg)](https://codecov.io/gh/io-sgr/geometry-common)This library is a simple JAVA / Android library that helps you transform coordinate between earth(WGS-84) and mars in China(GCJ-02).
*Read this in other languages: [English](README.md), [简体中文](README.zh-cn.md).*
Geometry Utilities requires at minimum Java 7 or Android 2.3.
## Usage
Convert coordinate from earth(WGS-84) to mars(GCJ-02):
```java
Coordinate mars = GeometryUtils.wgs2gcj(39.980945, 116.348120);
```
Convert coordinate from mars(GCJ-02) to earth(WGS-84):
```java
Coordinate earth = GeometryUtils.gcj2wgs(39.982296, 116.354308);
```## Advanced
To convert coordinates from WGS to GCJ or other way back, you need to know if the coordinate is inside **China mainland** or not.Common implementations use a **HUGE** box boundary which covers entire **China Mainland** and several regions like **Taiwan**, **Hong Kong** and **Macau** along with it to check the coordinate, which is not perfect.
To make sure you have the maximum accuracy and flexibility, Geometry Utilities provided two ways for you to achieve that goal:
### Default Implementation
By default, [GeometryUtils](src/main/java/io/sgr/geometry/utils/GeometryUtils.java) uses a [DefaultCoordinateChecker](src/main/java/io/sgr/geometry/utils/DefaultCoordinateChecker.java) to perform the check.The **DefaultCoordinateChecker** also uses a box boundary like other implementations but with **Taiwan**, **Hong Kong** and **Macau** excluded, which can cover most of the cases.
No additional code changes needed.
### Customized Implementation
If you are still not satisfied, you can write your own implementation very easily:
```java
public class CustomizedCoordinateChecker implements CoordinateChecker {
@Override
public boolean isOutOfChinaMainland(double lat, double lng) {
// Add your own logic here
return false;
}
}
GeometryUtils.setCoordinateChecker(new CustomizedCoordinateChecker());
```
You're all set!# License
Copyright 2017-2019 SgrAlpha
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.