android 개발 나의 고 덕 지도 코드 예

고 덕 지 도 를 다운로드 하여 라 이브 러 리 와 관련 등록 방식 에 의존 합 니 다. 고 덕 개발 자 사 이 트 를 보십시오.http://lbs.amap.com/api/android-sdk/summary  클릭 하여 링크 열기
고 덕 지도 좌표 픽업 기:http://lbs.amap.com/console/show/picker   클릭 하여 링크 열기
 keytool (jdk 자체 도구) 로 SHA 1 가 져 오기
다음 절차 에 따라 조작 합 니 다.
1. 콘 솔 에 들 어가 기 위해 실행 합 니 다.

2. 팝 업 콘 솔 창 에 cd. android 를 입력 하여. android 폴 더 로 이동 합 니 다.

3. 콘 솔 에 명령 을 계속 입력 합 니 다.
debug. keystore: 명령: keytool - list - v - keystore debug. keystore
사용자 정의 keystore: 명령: keytool - list - v - keystore apk 의 keystore
다음 과 같다.

키 라 이브 러 리 암 호 를 입력 하 는 것 을 알려 줍 니 다. 컴 파일 러 가 제공 하 는 debug keystore 의 기본 암 호 는 안 드 로 이 드 입 니 다. 사용자 정의 서명 파일 의 암 호 는 스스로 작성 하 십시오.키 를 입력 하고 차 로 돌아 갑 니 다 (비밀 번 호 를 설정 하지 않 으 면 바로 차 로 돌아 갈 수 있 습 니 다). 이 때 콘 솔 에 표 시 된 정보 에서 SHA 1 값 을 가 져 올 수 있 습 니 다. 아래 그림 과 같 습 니 다.

설명: keystore 파일 은 Android 서명 인증서 파일 입 니 다.
 
예 1:
package com.example.lenovo.mydemoapp;

import android.content.Intent;
import android.graphics.Point;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMap;
import com.amap.api.maps.AMapUtils;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.LocationSource;
import com.amap.api.maps.MapView;
import com.amap.api.maps.UiSettings;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;

import java.text.SimpleDateFormat;
import java.util.Date;

/*
name:     
time:2018-06-09 11:32:22
Can Enter:1.        SafeAreaConfirmation
return:1.             2.       
returnActivity:1.   
 */
// LocationSource          
public class EditSafeArea extends AppCompatActivity implements LocationSource,AMap.OnCameraChangeListener,AMapLocationListener {
    private SeekBar mSeekBar ;
    //       View
    private TextView mRadiusValue;
    private View mEditSafeAreaMapFence;
    //   
    private TextView mEditSafeAreaTheNextStepText;
    //aMap     
    private AMap aMap;
    //    
    private MapView mapView;
    //  AMapLocationClient           ,     
    private AMapLocationClient mLocationClient = null;
    //  mLocationOption              ,      `
    public AMapLocationClientOption mLocationOption = null;
    //  mListener  ,     
    private OnLocationChangedListener mListener = null;
    //  ,                      
    private boolean isFirstLoc = true;
    private AMapLocation aMapLocation ;
    private int mRadius;
    private LatLng mLatlng;
    private final String LATITUDE_KEY = "latitude_value";
    private final String LONGITUDE_KEY = "longitude_value";
    private final String RADIUS_KEY = "radius_value";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit_safe_area);
        //  
        mEditSafeAreaMapFence = (View)findViewById(R.id.EditSafeArea_MapFence);
        //   
        mSeekBar = (SeekBar)findViewById(R.id.EditSafeArea_SeekBar);
        //      
        mRadiusValue = (TextView)findViewById(R.id.EditSafeArea_radius_value);
        //   
        mEditSafeAreaTheNextStepText = (TextView)findViewById(R.id.EditSafeArea_TheNextStep_text);
        //      
        mapView = (MapView)findViewById(R.id.EditSafeArea_MapView);
        // activity  onCreate   mMapView.onCreate(savedInstanceState),          
        mapView.onCreate(savedInstanceState);
        if(aMap == null){
            //      
            aMap = mapView.getMap();
            //  UI   
            UiSettings settings = aMap.getUiSettings();
            //       
            aMap.setLocationSource(this);
            //         
            aMap.setOnCameraChangeListener(this);
            //         
            settings.setMyLocationButtonEnabled(true);
            //          
            aMap.setMyLocationEnabled(true);
        }
        //    
        location();
        //        
        mSeekBar.setProgress(0);
        //            ,     400       400
        mRadiusValue.setText(Integer.toString(mSeekBar.getProgress()+400));
        //         
        mEditSafeAreaMapFence.setLayoutParams(setFence());
        //     
        mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                //           
                mRadiusValue.setText(Integer.toString(progress+400));
                //       
                mEditSafeAreaMapFence.setLayoutParams(setFence());
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        //     
        mEditSafeAreaTheNextStepText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(EditSafeArea.this,SafeAreaConfirmation.class);
                if(mLatlng == null || mLatlng == null  || mRadius == 0 ){
                    Toast.makeText(EditSafeArea.this,"      ",Toast.LENGTH_SHORT).show();
                }else {
                    intent.putExtra(LATITUDE_KEY,mLatlng.latitude);
                    intent.putExtra(LONGITUDE_KEY,mLatlng.longitude);
                    intent.putExtra(RADIUS_KEY,mRadius);
                    Log.e("EditSafeArea","   mLatlng :"+mLatlng.latitude);
                    Log.e("EditSafeArea","   longitude :"+mLatlng.longitude);
                    Log.e("EditSafeArea","       :"+mRadius);
                    startActivity(intent);
                }


            }
        });

    }
    private void location() {

        //     
        mLocationClient = new AMapLocationClient(getApplicationContext());
        //         
        mLocationClient.setLocationListener(this);
        //         mLocationOption        
        mLocationOption = new AMapLocationClientOption();
        //       Hight_Accuracy     ,Battery_Saving      ,Device_Sensors      
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        //          (        )
        mLocationOption.setNeedAddress(true);
        //         ,   false
        mLocationOption.setOnceLocation(true);
        //        WIFI,       
        mLocationOption.setWifiActiveScan(true);
        //          ,   false,       
        mLocationOption.setMockEnable(false);
        //      ,    ,   2000ms
        mLocationOption.setInterval(5000);
        //              
        mLocationClient.setLocationOption(mLocationOption);
        //    
        mLocationClient.startLocation();

    }
    //                          ,        
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mLocationClient.stopLocation();//    
        mLocationClient.onDestroy();//    
    }
    //       
    @Override
    protected void onResume() {
        super.onResume();
        //      
        mapView.onResume();
    }
    //       
    @Override
    protected void onPause() {
        super.onPause();
        //    
        mapView.onPause();
    }
    //       
    @Override
    public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
        super.onSaveInstanceState(outState, outPersistentState);
        mapView.onSaveInstanceState(outState);
    }

    /*
                       :         ,         ,                  
    ,                  
     */

    @Override
    public void onLocationChanged(AMapLocation aMapLocation) {
        this.aMapLocation = aMapLocation;
        if (aMapLocation != null) {
            if (aMapLocation.getErrorCode() == 0) {
                //        ,      
                aMapLocation.getLocationType();//          ,       ,         
                aMapLocation.getLatitude();//    
                aMapLocation.getLongitude();//    
                aMapLocation.getAccuracy();//      
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date date = new Date(aMapLocation.getTime());
                df.format(date);//    
                aMapLocation.getAddress();//  ,  option   isNeedAddress false,      ,             ,GPS         。
                aMapLocation.getCountry();//    
                aMapLocation.getProvince();//   
                aMapLocation.getCity();//    
                aMapLocation.getDistrict();//    
                aMapLocation.getStreet();//    
                aMapLocation.getStreetNum();//       
                aMapLocation.getCityCode();//    
                aMapLocation.getAdCode();//    
                LatLng latLng = new LatLng(aMapLocation.getLatitude(),aMapLocation.getLongitude());
                if (isFirstLoc) {
                    //          moveCamera        CameraUpdateFactory         zoomBy   
                    aMap.moveCamera(CameraUpdateFactory.zoomTo(17));
                    //         ,              
                    aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude())));
                    //      
                    StringBuffer buffer = new StringBuffer();
                    buffer.append(aMapLocation.getCountry() + ""
                            + aMapLocation.getProvince() + ""
                            + aMapLocation.getCity() + ""
                            + aMapLocation.getProvince() + ""
                            + aMapLocation.getDistrict() + ""
                            + aMapLocation.getStreet() + ""
                            + aMapLocation.getStreetNum());
                    Toast.makeText(getApplicationContext(), buffer.toString(), Toast.LENGTH_LONG).show();
                    isFirstLoc = false;
                    Log.e("EditSafeArea","       :"+isFirstLoc);
                }
             } else {
                //      ErrCode    ,errInfo     ,      。
                Log.e("AmapError", "location Error, ErrCode:"
                        + aMapLocation.getErrorCode() + ", errInfo:"
                        + aMapLocation.getErrorInfo());
                Toast.makeText(getApplicationContext(), "    ", Toast.LENGTH_LONG).show();
             }
        }
    }
    //       ,                            
    @Override
    public void activate(OnLocationChangedListener onLocationChangedListener) {
        Log.e("EditSafeArea","      ");
        //      onLocationChangedListener          
        aMap.clear();
        aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude())));

        mListener = onLocationChangedListener;

    }
    //              
    @Override
    public void deactivate() {
        mListener = null;

    }

    //            
    @Override
    public void onCameraChange(CameraPosition cameraPosition) {
        mLatlng = cameraPosition.target;
        mEditSafeAreaMapFence.setLayoutParams(setFence());
        }

    //         
    @Override
    public void onCameraChangeFinish(CameraPosition cameraPosition) {
        mLatlng = cameraPosition.target;
        LatLng latLng  = cameraPosition.target;

    }
    //       
    public ViewGroup.LayoutParams setFence(){
        mRadius = Integer.parseInt(mRadiusValue.getText().toString());
        //            
        Point point = new Point();
        point.x = 0;
        point.y = 0;
        //              
        Point point1 = new Point();
        point1.x = 0;
        point1.y = 200;
        //             
        LatLng latLng = aMap.getProjection().fromScreenLocation(point);
        LatLng latLng1 = aMap.getProjection().fromScreenLocation(point1);
        Log.e("EditSafeArea","latLng_latitude:"+latLng.latitude+"latLng_longitude:"+latLng.longitude);
        Log.e("EditSafeArea","latLng1_latitude:"+latLng1.latitude+"latLng1_longitude:"+latLng1.longitude);
        //  2             ,    
        float distance = AMapUtils.calculateLineDistance(latLng,latLng1);
        Log.e("EditSafeArea","distance:"+distance);
        //      
        ViewGroup.LayoutParams layoutParams;
        layoutParams = mEditSafeAreaMapFence.getLayoutParams();
        //                
        int d = (int)(200 * mRadius / distance);
        //        200                      ,                  
        layoutParams.width = d+200;
        layoutParams.height = d+200;
        return  layoutParams;

    }
}

 
예 2:
package com.example.lenovo.mydemoapp;

import android.content.Intent;
import android.graphics.Color;
import android.os.PersistableBundle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.MapView;
import com.amap.api.maps.UiSettings;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.CircleOptions;
import com.amap.api.maps.model.LatLng;

/*
name:       
time:2018-06-09 11:32:22
Can Enter:1.   (     SafePlace)
return:1.          2.      3.     
returnActivity:SafePlace
 */
public class SafeAreaConfirmation extends AppCompatActivity {
    private MapView mapView;
    private AMap aMap;
    private EditText mSafeAreaConfirmationEditText;
    private Button mSafeAreaConfirmationSave;
    //          .      
    private AMapLocationClient mLocationClient;
    //              ,      `
    private AMapLocationClientOption mLocationOption;
    //
    private int mRadius ;
    private double mLatitude;
    private double mLongitude;
    //  /    key
    private final String LATITUDE_KEY = "latitude_value";
    private final String LONGITUDE_KEY = "longitude_value";
    private final String RADIUS_KEY = "radius_value";
    private final String NAME_KEY = "name_value";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_safe_area_confirmation);
        mSafeAreaConfirmationEditText = (EditText)findViewById(R.id.SafeAreaConfirmation_EditText);
        mSafeAreaConfirmationSave = (Button)findViewById(R.id.SafeAreaConfirmation_save);
        mapView = (MapView)findViewById(R.id.SafeAreaConfirmation_MapView);
        mapView.onCreate(savedInstanceState);
        if(aMap == null){
            aMap = mapView.getMap();
            UiSettings uiSettings = aMap.getUiSettings();
            //       
            uiSettings.setMyLocationButtonEnabled(false);
            //       
            uiSettings.setZoomControlsEnabled(false);
            //            
            uiSettings.setZoomGesturesEnabled(false);
            //            
            uiSettings.setScrollGesturesEnabled(false);
            //            
            uiSettings.setRotateGesturesEnabled(false);
            //         
            aMap.setMyLocationEnabled(false);
        }
        location();
        displayFence();
        //        
        mSafeAreaConfirmationSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mSafeAreaConfirmationEditText.getText().toString().equals("")){
                    Toast.makeText(SafeAreaConfirmation.this,"        ",Toast.LENGTH_SHORT).show();
                    Log.e("SafeAreaConfirmation","         ");
                }else {
                    Log.e("SafeAreaConfirmation","       :"+mSafeAreaConfirmationEditText.getText().toString());
                    Intent intent = new Intent(SafeAreaConfirmation.this,SafePlace.class);
                    intent.putExtra(LATITUDE_KEY,mLatitude);
                    intent.putExtra(LONGITUDE_KEY,mLongitude);
                    intent.putExtra(RADIUS_KEY,mRadius);
                    intent.putExtra(NAME_KEY,mSafeAreaConfirmationEditText.getText().toString());
                    startActivity(intent);
                }

            }
        });
    }

    //                          ,        
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mLocationClient.stopLocation();//    
        mLocationClient.onDestroy();//    
    }
    //       
    @Override
    protected void onResume() {
        super.onResume();
        //      
        mapView.onResume();
    }
    //       
    @Override
    protected void onPause() {
        super.onPause();
        //    
        mapView.onPause();
    }
    //       
    @Override
    public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
        super.onSaveInstanceState(outState, outPersistentState);
        mapView.onSaveInstanceState(outState);
    }
    //       
    private void location() {
        //     
        mLocationClient = new AMapLocationClient(getApplicationContext());
        //         mLocationOption        
        mLocationOption = new AMapLocationClientOption();
        //       Hight_Accuracy     ,Battery_Saving      ,Device_Sensors      
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        //         ,   false
        mLocationOption.setOnceLocation(true);
        //        WIFI,       
        mLocationOption.setWifiActiveScan(true);
        //          ,   false,       
        mLocationOption.setMockEnable(false);
        //      ,    ,   2000ms
        mLocationOption.setInterval(5000);
        //              
        mLocationClient.setLocationOption(mLocationOption);
    }

    //       
    public void displayFence(){
        Intent intent = getIntent();
        mLatitude = intent.getDoubleExtra(LATITUDE_KEY,0);
        mLongitude = intent.getDoubleExtra(LONGITUDE_KEY,0);
        mRadius = intent.getIntExtra(RADIUS_KEY,0);
        //   
        CircleOptions circleOptions = new CircleOptions();
        if(mLatitude != 0 && mLongitude != 0 && mRadius != 0){
            LatLng latLng = new LatLng(mLatitude,mLongitude);
            aMap.moveCamera(CameraUpdateFactory.changeLatLng(latLng));
            //          
            if (mRadius < 200){
                aMap.moveCamera(CameraUpdateFactory.zoomTo(17));
            }else if(mRadius < 400){
                aMap.moveCamera(CameraUpdateFactory.zoomTo(16));
            }else if (mRadius < 700){
                aMap.moveCamera(CameraUpdateFactory.zoomTo(15));
            }else if (mRadius <= 1300){
                aMap.moveCamera(CameraUpdateFactory.zoomTo(14));
            }
            //     
            circleOptions.center(latLng);
            //     
            Log.e("SafeAreaConfirmation","radius is:"+mRadius);
            circleOptions.radius(mRadius);
            //       
            circleOptions.strokeWidth(4);
            //    
            circleOptions.strokeColor(Color.argb(255,0,140,237));
            //  
            circleOptions.fillColor(Color.argb(50,99,184,255));
            aMap.addCircle(circleOptions);

        }else {
            Log.e("SafeAreaConfirmation","latitude and longitude and radius is empty");
        }




    }
}

지도 에 표 시 된 사용자 정의:
 //      
    public void addMapMark(int position){
        MarkerOptions markerOption = new MarkerOptions();
        markerOption.position(listData.getLatLng());
        markerOption.title(listData.getName());
        markerOption.draggable(false);
        Bitmap bt = BitmapFactory.decodeFile(listData.getFilePath());
        if(bt != null){
            markerOption.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory
                    .decodeFile(listData.getFilePath())));
        }else {
            Log.e(TAG, "       ,      ");
            markerOption.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory
                    .decodeResource(getResources(),R.mipmap.default_avatar1)));
        }

        aMap.addMarker(markerOption);
    }

좌표 에 따라 주소 획득:
우선 class 에서 인터페이스 해 야 합 니 다:
public class MainActivity extends BaseActivity implements GeocodeSearch.OnGeocodeSearchListener

그리고 좌표 값 을 입력 합 니 다.
    /**
     *         
     * @param latLng    
     */
    public void getAddress(LatLng latLng){
        geocodeSearch = new GeocodeSearch(this);
        geocodeSearch.setOnGeocodeSearchListener(this);
        Log.e(TAG, "getAddress    :"+"latitude:" +latLng.latitude+"longitude:"+latLng.longitude);
        LatLonPoint latLonPoint = new LatLonPoint(latLng.latitude,latLng.longitude);
        RegeocodeQuery regeocodeQuery = new RegeocodeQuery(latLonPoint,200,GeocodeSearch.AMAP);//     、  、   
        geocodeSearch.getFromLocationAsyn(regeocodeQuery);
    }

좌표 의 지도 주소 텍스트 반전 가 져 오기
@Override  //               
    public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {
        //1000               
        if( i == 1000){
            Log.e(TAG, "onRegeocodeSearched   i: "+i );
            RegeocodeAddress regeocodeAddress = regeocodeResult.getRegeocodeAddress();
            address = regeocodeAddress.getFormatAddress();
            Log.e(TAG, "onRegeocodeSearched  : "+mAddress);
            mAddress.setText(address);
        }else {
            Log.e(TAG, "onRegeocodeSearched   i: "+i );
        }

    }

    @Override
    public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {
        //           ,   
    }

좋은 웹페이지 즐겨찾기