Skip to content

Instantly share code, notes, and snippets.

@ihipop
Created January 4, 2016 07:54
Show Gist options
  • Save ihipop/4db0f10f51692a21ba10 to your computer and use it in GitHub Desktop.
Save ihipop/4db0f10f51692a21ba10 to your computer and use it in GitHub Desktop.
大众点评坐标解密样例代码
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
class test(object):
def base36encode(self,number):
"""Converts an integer into a base36 string."""
# From https://gist.github.com/kfr2/4287546
import string
ALPHABET = string.digits+string.ascii_lowercase
if not isinstance(number,int):
raise TypeError('This function must be called on an integer.')
base36 = ''
sign = ''
if number < 0:
sign = '-'
number = -number
if 0 <= number < len(ALPHABET):
return sign + ALPHABET[number]
while number != 0:
number, i = divmod(number, len(ALPHABET))
base36 = ALPHABET[i] + base36
return sign + base36
def decodeDzLonLat(self,string):
C = string
digi = 16
add = 10
plus = 7
cha = 36
I = -1
H = 0
B = ''
J = len(C)
G = ord(C[-1])
C = C[:-1]
J -= 1
for E in range(J):
D = int(C[E], cha) - add
if D >= add:
D = D - plus
B += self.base36encode(D)
if D > H:
I = E
H = D
A = int(B[:I], digi)
F = int(B[I+1:], digi)
L = (A + F - int(G)) / 2
K = float(F - L) / 100000
L = float(L) / 100000
return {'lat': K, 'lng': L}
#HEVIWRZVVJTJGJ =>39.87955,116.49699
a = test()
print(a.decodeDzLonLat('HEVIWRZVVJTJGJ'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment