Skip to content

Commit 86f4781

Browse files
committed
build(kotlin): Port SphericalMercatorProjection to Kotlin
1 parent 0bb1d34 commit 86f4781

File tree

5 files changed

+291
-419
lines changed

5 files changed

+291
-419
lines changed

library/src/main/java/com/google/maps/android/clustering/algo/NonHierarchicalDistanceBasedAlgorithm.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.google.maps.android.projection.SphericalMercatorProjection;
2525
import com.google.maps.android.quadtree.PointQuadTree;
2626

27-
import java.util.ArrayList;
2827
import java.util.Collection;
2928
import java.util.Collections;
3029
import java.util.HashMap;

library/src/main/java/com/google/maps/android/projection/SphericalMercatorProjection.java

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2013 Google LLC.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.maps.android.projection
18+
19+
import com.google.android.gms.maps.model.LatLng
20+
import com.google.maps.android.geometry.Point
21+
import kotlin.math.*
22+
23+
class SphericalMercatorProjection(private val worldWidth: Double) {
24+
25+
fun toPoint(latLng: LatLng): Point {
26+
val x = latLng.longitude / 360 + 0.5
27+
val siny = sin(Math.toRadians(latLng.latitude))
28+
val y = 0.5 * ln((1 + siny) / (1 - siny)) / -(2 * Math.PI) + 0.5
29+
return Point(x * worldWidth, y * worldWidth)
30+
}
31+
32+
fun toLatLng(point: Point): LatLng {
33+
val x = point.x / worldWidth - 0.5
34+
val lng = x * 360
35+
val y = 0.5 - (point.y / worldWidth)
36+
val lat = 90 - Math.toDegrees(atan(exp(-y * 2 * Math.PI)) * 2)
37+
return LatLng(lat, lng)
38+
}
39+
}

0 commit comments

Comments
 (0)