2017-09-26 4 views
0

Comment correctement atteindre cela après avoir entré les coordonnées, il a placé le marqueur, mais n'a pas dit que "rien n'est trouvé" comme indiqué dans l'image?PlaceAutocomplete - entrez les coordonnées

enter image description here

Mes doivent attraper conjectures ce statut d'erreur comme suit:

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    try { 
     switch(requestCode){ 
      case PLACE_AUTOCOMPLETE_REQUEST_CODE: 
       switch(resultCode){ 
        case RESULT_OK: 
         ... 
         break; 
        case RESULT_ERROR: 
         if (!PlaceAutocomplete.getStatus(this, data).isSuccess()) { 
           markerPlace = map.addMarker(new MarkerOptions().position(PlaceAutocomplete.getPlace(this, data).getLatLng()).icon(vectorToBitmap(R.drawable.ic_place_black_24dp, ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark)))); 
           autocompleteFragment.setText(PlaceAutocomplete.getPlace(this, data).getLatLng() + ""); 
         } 
         break; 
        } 
        break; 
      } 
     } catch (NullPointerException ex) { 
      ex.printStackTrace(); 
     } 

Mais cela ne fonctionne pas ...

post-scriptum Désolé pour mon anglais.

+0

Est-ce que PlaceAutoComplete fonctionne avec les coordonnées? N'est-ce pas censé être un nom de lieu? –

+0

@ EmreAktürk avec un nom de lieu de travail parfait, mais avec des coordonnées ne fonctionne pas :( – iFr0z

+0

Peut-être que ses coordonnées de soutien ne sont pas –

Répondre

0

Malheureusement, je ne trouve rien officiel.

MAIS

post-scriptum oublier PlaceAutocomplete.


DURES


Begin conception: CustomSearchBox

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    card_view:cardCornerRadius="3dp" 
    card_view:cardElevation="3dp" 
    card_view:cardPreventCornerOverlap="false" 
    card_view:cardUseCompatPadding="true"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/tool_bar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     app:theme="@style/ToolbarColoredBackArrowBlack"> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 

      <CustomEditText 
       android:id="@+id/searchPlace" 
       style="@style/CustomEditViaGoogleMaps" 
       android:layout_height="wrap_content" 
       android:layout_width="0dp" 
       android:layout_weight="1.8" 
       android:cursorVisible="false" 
       android:ellipsize="end" 
       android:hint="@string/place_search_hint" 
       android:imeOptions="actionSearch|flagNoFullscreen" 
       android:inputType="numberDecimal" 
       android:digits=".," 
       android:maxLines="1" 
       android:scrollHorizontally="true" 
       android:textColor="@android:color/black" 
       android:textSize="20sp" /> 

      <ImageView 
       android:id="@+id/clearSearch" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.2" 
       android:layout_gravity="center" 
       android:layout_marginStart="9dp" 
       android:layout_marginEnd="14dp" 
       android:visibility="gone" 
       android:contentDescription="@string/app_name" 
       app:srcCompat="@drawable/ic_clear_black_24dp" /> 

     </LinearLayout> 

    </android.support.v7.widget.Toolbar> 

</android.support.v7.widget.CardView> 

Style:

<style name="ToolbarColoredBackArrowBlack" parent="AppTheme"> 
     <item name="android:textColorSecondary">@color/color_toolbar_via_google_maps</item> 
     <item name="android:textColorPrimary">@color/color_toolbar_via_google_maps</item> 
    </style> 

<style name="CustomEditViaGoogleMaps"> 
     <item name="android:theme">@style/EditAppThemeViaGoogleMaps</item> 
    </style> 
    <style name="EditAppThemeViaGoogleMaps"> 
     <item name="colorControlActivated">@color/color_toolbar_via_google_maps</item> 
     <item name="colorAccent">@color/colorAccent</item> 
     <item name="android:textColorHint">@color/color_text_toolbar_via_google_maps</item> 
     <item name="colorControlNormal">@android:color/white</item> 
     <item name="colorControlHighlight">@android:color/white</item> 
     <item name="android:colorButtonNormal">@android:color/white</item> 
    </style> 

Couleur:

<color name="color_toolbar_via_google_maps">#616161</color> 
<color name="color_text_toolbar_via_google_maps">#BDBDBD</color> 

Résultat:

введите сюда описание изображения

Java

Marker markerPlace; 
CustomEditText placeSearch; 
ImageView clearSearch; 
... 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    .... 
    placeSearch = findViewById(R.id.searchPlace); 
    clearSearch = findViewById(R.id.clearSearch); 
    placeSearch(); 
} 

public void placeSearch() { 
    placeSearch.getBackground().setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);//line edit to white 
    placeSearch.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      placeSearch.setCursorVisible(true); 
     } 
    }); 
    placeSearch.setOnEditorActionListener(new EditText.OnEditorActionListener() { 
     @Override 
     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
      if (actionId == EditorInfo.IME_ACTION_SEARCH) { 
       ((InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(placeSearch.getWindowToken(), 0); 
       placeSearch.setCursorVisible(false); 
       String[] latLng = placeSearch.getText().toString().split(","); 
       if (markerPlace != null) map.clear(); 
       markerPlace = map.addMarker(new MarkerOptions().position(new LatLng(Double.parseDouble(latLng[0]), Double.parseDouble(latLng[1]))).icon(vectorToBitmap(R.drawable.ic_place_black_24dp, ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark)))); 
       map.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder().target(new LatLng(Double.parseDouble(latLng[0]), Double.parseDouble(latLng[1]))).zoom((float) 15.5).bearing(360).tilt(0).build())); 
       markerPlace.setTitle(placeSearch.getText() + ""); 
       markerPlace.showInfoWindow(); 
       return true; 
      } 
      return false; 
     } 
    }); 
    placeSearch.addTextChangedListener(new TextWatcher() { 
     @Override 
     public void afterTextChanged(Editable s) {} 
     @Override 
     public void beforeTextChanged(CharSequence s, int start, int count, int after) {} 
     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) { 
      if (s.length() > 0) clearSearch.setVisibility(View.VISIBLE); 
      else clearSearch.setVisibility(View.GONE); 
     } 
    }); 
    clearSearch.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      markerPlace = null; 
      map.clear(); 
      placeSearch.setText(""); 
     } 
    }); 
} 

public class CustomEditText extends AppCompatEditText { 

    Context context; 
    CustomEditText placeSearch; 

    public CustomEditText(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     this.context = context; 
    } 

    @Override 
    public boolean onKeyPreIme(int keyCode, KeyEvent event) { 
     if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { 
      ((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(this.getWindowToken(), 0); 
      placeSearch = findViewById(R.id.searchPlace); 
      placeSearch.setCursorVisible(false); 
     } 
     return false; 
    } 

} 

Résultat 2:

введите сюда описание изображения

Résultat 3:

введите сюда описание изображения

Bonne chance :)

0

Il ne supporte que la recherche de nom, en d'autres termes, il n'y a pas d'endroit qui s'appelle 55,33.00.

Vous pouvez vérifier Place Autocomplete Documantation quelle référence de recherche par programme, n'a pas vu de méthode pour laisser l'utilisateur de recherche avec latlng.

Place picker est ce que vous cherchez.

Bonne chance

Emre

+0

dans la documentation ce n'est pas écrit ... il est trop tôt pour tirer de telles conclusions – iFr0z