주소로부터 위도 경도를 얻어올수있나요?

조회수 2431회

주소를가지고 구글맵스에 위치를 표시하고 싶은데요. Google Maps API를 사용해서 주소로부터 위도 경도를 받아 올 수 있나요?

1 답변

  • 좋아요

    0

    싫어요
    채택 취소하기
    public GeoPoint getLocationFromAddress(String strAddress){
    
    Geocoder coder = new Geocoder(this);
    List<Address> address;
    GeoPoint p1 = null;
    
    try {
        address = coder.getFromLocationName(strAddress,5);
        if (address==null) {
           return null;
        }
        Address location=address.get(0);
        location.getLatitude();
        location.getLongitude();
    
        p1 = new GeoPoint((int) (location.getLatitude() * 1E6),
                          (int) (location.getLongitude() * 1E6));
    
        return p1;
        }
    }
    

    strAddress는 주소를 포함한 문자열이고 address 변수는 변환된 주소를 저장합니다.

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)