Android Open Source - android-maps-utils Spherical Mercator Projection






From Project

Back to project page android-maps-utils.

License

The source code is released under:

Apache License

If you think the Android project android-maps-utils listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2013 Google Inc./*w ww . ja va 2 s . c  o  m*/
 *
 * 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;

public class SphericalMercatorProjection {
    final double mWorldWidth;

    public SphericalMercatorProjection(final double worldWidth) {
        mWorldWidth = worldWidth;
    }

    @SuppressWarnings("deprecation")
    public Point toPoint(final LatLng latLng) {
        final double x = latLng.longitude / 360 + .5;
        final double siny = Math.sin(Math.toRadians(latLng.latitude));
        final double y = 0.5 * Math.log((1 + siny) / (1 - siny)) / -(2 * Math.PI) + .5;

        return new Point(x * mWorldWidth, y * mWorldWidth);
    }

    public LatLng toLatLng(com.google.maps.android.geometry.Point point) {
        final double x = point.x / mWorldWidth - 0.5;
        final double lng = x * 360;

        double y = .5 - (point.y / mWorldWidth);
        final double lat = 90 - Math.toDegrees(Math.atan(Math.exp(-y * 2 * Math.PI)) * 2);

        return new LatLng(lat, lng);
    }
}




Java Source Code List

com.google.maps.android.MarkerManager.java
com.google.maps.android.MathUtil.java
com.google.maps.android.PolyUtil.java
com.google.maps.android.SphericalUtil.java
com.google.maps.android.clustering.ClusterItem.java
com.google.maps.android.clustering.ClusterManager.java
com.google.maps.android.clustering.Cluster.java
com.google.maps.android.clustering.algo.Algorithm.java
com.google.maps.android.clustering.algo.GridBasedAlgorithm.java
com.google.maps.android.clustering.algo.NonHierarchicalDistanceBasedAlgorithm.java
com.google.maps.android.clustering.algo.PreCachingAlgorithmDecorator.java
com.google.maps.android.clustering.algo.StaticCluster.java
com.google.maps.android.clustering.view.ClusterRenderer.java
com.google.maps.android.clustering.view.DefaultClusterRenderer.java
com.google.maps.android.geometry.Bounds.java
com.google.maps.android.geometry.Point.java
com.google.maps.android.heatmaps.Gradient.java
com.google.maps.android.heatmaps.HeatmapTileProvider.java
com.google.maps.android.heatmaps.WeightedLatLng.java
com.google.maps.android.projection.Point.java
com.google.maps.android.projection.SphericalMercatorProjection.java
com.google.maps.android.quadtree.PointQuadTree.java
com.google.maps.android.ui.BubbleDrawable.java
com.google.maps.android.ui.BubbleIconFactory.java
com.google.maps.android.ui.IconGenerator.java
com.google.maps.android.ui.RotationLayout.java
com.google.maps.android.ui.SquareTextView.java
com.google.maps.android.utils.demo.BaseDemoActivity.java
com.google.maps.android.utils.demo.BigClusteringDemoActivity.java
com.google.maps.android.utils.demo.ClusteringDemoActivity.java
com.google.maps.android.utils.demo.CustomMarkerClusteringDemoActivity.java
com.google.maps.android.utils.demo.DistanceDemoActivity.java
com.google.maps.android.utils.demo.HeatmapsDemoActivity.java
com.google.maps.android.utils.demo.HeatmapsPlacesDemoActivity.java
com.google.maps.android.utils.demo.IconGeneratorDemoActivity.java
com.google.maps.android.utils.demo.MainActivity.java
com.google.maps.android.utils.demo.MultiDrawable.java
com.google.maps.android.utils.demo.MyItemReader.java
com.google.maps.android.utils.demo.PolyDecodeDemoActivity.java
com.google.maps.android.utils.demo.TileProviderAndProjectionDemo.java
com.google.maps.android.utils.demo.model.MyItem.java
com.google.maps.android.utils.demo.model.Person.java