인코딩 된 폴리 라인을 사용하여 정적지도에서 여러 점 사이의 경로를 나타내려고합니다. 이 코드는 다음처럼 정의 getStaticMapAddress라는 함수이다 :Google 정적지도 API : 경로를 인코딩 된 폴리선으로 나타 내기
def getStaticMapAddress(self, route):
destUser = DestUser(self.destination)
route += [destUser]
attempts = 0
while attempts < 10:
try:
encodedPolyline = self.encodePolyLine(route)
break
except googlemaps.GoogleMapsError:
print "Error. Try again"
attempts += 1
url = "http://maps.google.com/maps/api/staticmap?zoom="+encodedPolyline[1]+"&sensor=false&size=400x400&markers="
i=0
while i<len(route):
url += str(route[i].location.lat)+","+str(route[i].location.lng)
i=i+1
if i < len(route):
url += "|"
url += "&path=color:0xff0000ff|weight:5|enc:"+encodedPolyline[0]
return url
경로는 사용자 오브젝트 (어느 DestUser는 서브 클래스)의리스트로 표시된다. 다음과 같이 self.encodePolyLine() 메소드가 정의된다
def encodePolyLine(self, route):
routePairs = []
destUser = DestUser(self.destination)
route += [destUser]
i=0
while (i < len(route)-1):
# GET ALL TURNING POINTS FOR EACH POINT ON ROUTE, THEN PUT THEM
# IN PAIRS AND SEND THEM TO glineenc.encode_pairs()
for step in gmaps.directions(gmaps.latlng_to_address(route[i].location.lat, route[i].location.lng), gmaps.latlng_to_address(route[i+1].location.lat, route[i+1].location.lng))['Directions']['Routes'][0]['Steps']:
routePairs += [(step['Point']['coordinates'][0], step['Point']['coordinates'][1])]
i=i+1
return glineenc.encode_pairs(routePairs)
이 glineenc 모듈 here 내지 최대 줌을 나타내는 인코딩 된 광고 문자열을 포함하는 쌍 및 코드 스트링을 반환 좌표 쌍들의리스트에 걸리는 모든 포인트를 볼 수있는 레벨. 그래서 브라이튼, 런던, 브리스톨, 맨체스터 사이를 오가며이 기능에 합격했습니다. 다음 URL은 출력물입니다.
http://maps.google.com/maps/api/[email protected]@@@@[email protected]@[email protected]@[email protected]@[email protected]@@@@@@@[email protected]@@@@[email protected]@@@@@[email protected]@[email protected]@@@@@@B&sensor=false&size=400x400&markers=50.8202008,-0.1324898|51.447341,-0.0761212|51.4608947,-2.5884312|53.4778853,-2.2308146|53.4778853,-2.2308146&path=color:0xff0000ff|weight:5|enc:b|[email protected]@{BlJgDqHaZkEy[[email protected]@}[email protected]_BqxDmC`[email protected]_Rq|[email protected]`xD_cAzBpBvNM{HsHh]wNfbCzOxpCrUjeD_`[email protected]`D_PjctLa}BzhH~nFn\[email protected]@dC`[email protected][email protected]~AmAzDsW_Ak_CmiAkuGy_GvxDctEolnBcpdEhtPc}[email protected]`]kiCr]opDtRcW}[email protected]
이 파일을 보면 잘못된 것이 있음을 알 수 있습니다. 나는 정확히 어떤 일이 일어 났는지 확신 할 수 없지만, 적도와 경선을 대칭 선으로 사용하면 새로운 경로가 올바른 경로의 투영 인 것으로 나타났습니다. 왜 이런 일을했을지 모르겠지만 그게 문제의 가능한 원인으로 볼 수있는 전부입니다. 어떤 아이디어?