Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.maps.android.projection.SphericalMercatorProjection;
import com.google.maps.android.quadtree.PointQuadTree;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2025 Google LLC.
*
* 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.
*/

package com.google.maps.android.projection

import com.google.android.gms.maps.model.LatLng
import com.google.maps.android.geometry.Point
import kotlin.math.*

class SphericalMercatorProjection(private val worldWidth: Double) {

fun toPoint(latLng: LatLng): Point {
val x = latLng.longitude / 360 + 0.5
val siny = sin(Math.toRadians(latLng.latitude))
val y = 0.5 * ln((1 + siny) / (1 - siny)) / -(2 * Math.PI) + 0.5
return Point(x * worldWidth, y * worldWidth)
}

fun toLatLng(point: Point): LatLng {
val x = point.x / worldWidth - 0.5
val lng = x * 360
val y = 0.5 - (point.y / worldWidth)
val lat = 90 - Math.toDegrees(atan(exp(-y * 2 * Math.PI)) * 2)
return LatLng(lat, lng)
}
}
Loading