"일꾼이 일을 잘하려면 먼저 도구를 갈고 닦아야 한다." - 공자, 『논어』.
첫 장 > 프로그램 작성 > Google Maps API v2를 사용하여 운전 경로를 찾는 방법은 무엇입니까?

Google Maps API v2를 사용하여 운전 경로를 찾는 방법은 무엇입니까?

2024-11-09에 게시됨
검색:953

How to Get Driving Directions Using Google Maps API v2?

Google Maps API v2로 운전 경로 찾기

질문에 언급하신 요청은 Google Maps API의 addPolyline 메소드를 활용합니다. 두 점 사이에 직선을 그리는 것입니다. 이 메소드는 운전 경로를 검색하기 위한 것이 아니라 지도에 간단한 선을 표시하기 위한 것입니다.

두 위치 간의 자세한 운전 지침을 얻으려면 Google Maps Directions API를 애플리케이션에 통합해야 합니다. 제공하신 답변에서 언급한 대로 AKExorcist에서 만든 라이브러리는 이 작업에 편리한 옵션입니다.

다음은 이 라이브러리를 사용하여 운전 경로를 검색하는 방법을 보여주는 샘플 코드 조각입니다.

import akexorcist.googledirection.DirectionCallback;
import akexorcist.googledirection.GoogleDirection;
import akexorcist.googledirection.constant.TransportMode;
import akexorcist.googledirection.model.Direction;

// Initialize GoogleDirection
GoogleDirection googleDirection = new GoogleDirection(apiKey);

// Set the departure and arrival locations
LatLng origin = new LatLng(12.917745600000000000, 77.623788300000000000);
LatLng destination = new LatLng(12.842056800000000000, 7.663096499999940000);

// Request directions
googleDirection.withTransportMode(TransportMode.DRIVING)
        .withOrigin(origin)
        .withDestination(destination)
        .execute(new DirectionCallback() {
            @Override
            public void onDirectionSuccess(Direction direction, String rawBody) {
                // Process and display driving directions
            }

            @Override
            public void onDirectionFailure(Throwable t) {
                // Handle direction retrieval error
            }
        });

이 코드는 GoogleDirection 라이브러리를 사용하여 지정된 지점 사이의 운전 경로를 검색합니다. 검색에 성공하면 onDirectionSuccess 콜백 메소드가 호출되어 지침, 기간 및 거리가 포함된 방향 객체에 대한 액세스를 제공합니다.

최신 튜토리얼 더>

부인 성명: 제공된 모든 리소스는 부분적으로 인터넷에서 가져온 것입니다. 귀하의 저작권이나 기타 권리 및 이익이 침해된 경우 자세한 이유를 설명하고 저작권 또는 권리 및 이익에 대한 증거를 제공한 후 이메일([email protected])로 보내주십시오. 최대한 빨리 처리해 드리겠습니다.

Copyright© 2022 湘ICP备2022001581号-3