2016-12-06 62 views
1

我有經緯度和經度從谷歌AutoComplete片段到Realm DB的問題。我在文本視圖中獲取數據,但無法將此數據作爲Double傳遞給Realm DB。 horse.setLocationLatitude在境界谷歌地方的自動完成片段通過雙緯度/經緯DB

private void saveHorseInRealm() { 

    getRealm().beginTransaction(); 
    Horse horse = getRealm().createObject(Horse.class); 

    Long tsLong = System.currentTimeMillis()/1000; 
    String ts = tsLong.toString(); 
    horse.setID(ts); 

    horse.setName(mNameEditText.getText().toString()); 
    horse.setLocationName(mLocationNam.getText().toString()); 
    horse.setLocationLatitude(mLocationLat); 
    horse.setLocationLongitude(mLocationLon); 
      getRealm().commitTransaction(); 

    getActivity().onBackPressed(); 
} 
+0

這是什麼版本的Realm? – EpicPandaForce

回答

0
horse.setLocationLatitude(Double.valueOf(mLocationLat.getText().toString())); 
horse.setLocationLongitude(Double.valueOf(mLocationLon.getText().toString())); 

設置爲雙

final LinearLayout mLinearLayout = (LinearLayout) inflater.inflate(
      R.layout.fragment_add_horse, container, false); 


    PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment) getActivity().getFragmentManager().findFragmentById(R.id.autocomplete_fragment); 
    autocompleteFragment.setHint("Enter Location"); 
    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() { 
     @Override 
     public void onPlaceSelected(Place place) { 
      mLocationNam.setText("Place: " + place.getName().toString()); 
      System.out.println("Place: " + place.getName()); 
      mLocationLat.setText("" + place.getLatLng().latitude); 
      mLocationLon.setText("" + place.getLatLng().longitude); 

     } 

     @Override 
     public void onError(Status status) { 
      System.out.println("An error occurred: " + status); 
     } 
    }); 

    return mLinearLayout; 

} 

    public void onViewCreated(View view, Bundle savedInstanceState) { 
    super.onViewCreated(view, savedInstanceState); 
    mLocationNam = (TextView) view.findViewById(R.id.loc_name); 

    mLocationLat = (TextView) view.findViewById(R.id.loc_lat); 
    mLocationLon = (TextView) view.findViewById(R.id.loc_lon);} 

節能雖然你應該抽象數據從視圖自身using TextWatchers