2017-05-03 1 views

답변

2

먼저이 같은 당신을 찾아야한다 모델 클래스를 만들 필요가 같은 시간 :이처럼 Activity에 변수를 만들 필요가보다

public class MapModel { 
    private String latitude; 
    private String longitude; 

    public MapModel() {} 

    public MapModel(String latitude, String longitude) { 
     this.latitude = latitude; 
     this.longitude = longitude; 
    } 

    public void setLatitude(String latitude) {this.latitude = latitude;} 
    public String getLatitude() {return latitude;} 

    public void setLongitude(String longitude) {this.longitude = longitude;} 
    public String getLongitude() {return longitude;} 
} 

:

private static final int PLACE_PICKER_REQUEST = 123; 
onActivityResult 무시

그것은 다음과 같아야합니다

@Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     if (requestCode == PLACE_PICKER_REQUEST){ 
      if (resultCode == RESULT_OK) { 
       Place place = PlacePicker.getPlace(this, data); 
       if (place != null){ 
        LatLng latLng = place.getLatLng(); 
        MapModel mapModel = new MapModel(latLng.latitude + "", latLng.longitude + ""); 
        databaseReference.push().setValue(mapModel); 
       } 
      } 
     } 
    } 

이 위치를 보내려면 다음과 같은 방법을 만들 :

private void locationPlacesIntent(){ 
    try { 
     PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder(); 
     startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST); 
    } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) { 
     e.printStackTrace(); 
    } 
} 

그것이 도움이되기를 바랍니다.

+0

위치를 보내 주셨습니까? –