Android examples for Map:Location
GeoPo Location Encode in Java.
/* ------------------------------------------------------------------------ * Copyright 2010, Handy Codeworks LLC/*from ww w .ja v a 2 s . co 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.java2s; public class Main { /** * GeoPo Encode in Java. * * @param lat latitude * @param lng longnitude * @param scale scale of map * @return geopo code */ public static String encode(double lat, double lng, int scale) { // 64characters (number + big and small letter + hyphen + underscore). final String chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_"; StringBuffer geopo = new StringBuffer(); lat = (lat + 90) / 180 * Math.pow(8, 10); lng = (lng + 180) / 360 * Math.pow(8, 10); for (int i = 0; i < scale; i++) { geopo.append(chars.charAt((int) (Math.floor(lat / Math.pow(8, 9 - i) % 8) + Math.floor(lng / Math.pow(8, 9 - i) % 8) * 8))); } return geopo.toString(); } }