-1

Я хочу создать приложение, которое показывает мне местоположение пользователя на карте google ... но оно показывает мне, что адрес не найден .. Даже когда я пытался дать фиксированное значение ...No Location Found In Geocoder Asyncktask Activity

 if(location!=null && !location.equals("")){ 
        googleMap.clear(); 
        new GeocoderTask(MainActivityMap.this).execute(location); 

       } 

Мои Geocoder AsyncTask активность

 private class GeocoderTask extends AsyncTask<String, Void, List<Address>>{ 
      private Context mainContxt; 
      Geocoder geocoder; 
      public GeocoderTask(Context con){ 
      mainContxt=con; 

      } 

      @Override 
      protected List<Address> doInBackground(String... locationName) { 
       Geocoder geocoder = new Geocoder(mainContxt); 
        List<Address> addresses = null; 

        try { 
         addresses = geocoder.getFromLocationName(locationName[0], 3); 
        } catch (IOException e) { 
         e.printStackTrace(); 
        } 
        return addresses; 
      } 


      @Override 
      protected void onPostExecute(List<Address> addresses) { 


     if(addresses==null || addresses.size()==0){ 
     Toast.makeText(getBaseContext(), "No Location found.Please check  

     address", Toast.LENGTH_SHORT).show(); 
     return; // add this 
     } 
     else{ 

       for(int i=0;i<addresses.size();i++){    

        Address address = (Address) addresses.get(i); 
        latLng = new LatLng(address.getLatitude(), address.getLongitude()); 

        String addressText = String.format("%s, %s", 
          address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "", 
          address.getCountryName()); 

        markerOptions = new MarkerOptions(); 
        markerOptions.position(latLng); 
        markerOptions.title(addressText); 
        if(i==0) { 
        googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng)); 
        } 
        googleMap.addMarker(markerOptions); 


       } 
      } 
      } 
     } 

я думаю, что ошибка в этой строке

addresses = geocoder.getFromLocationName(locationName[0], 3); 

адрес Rece доцент ive ничего .... thx заранее ... помогите мне друзья

+0

Почему вы не используете долготу и широту для этого? –

+0

@chirag Как использовать широту и долготу в этом виде деятельности – Tufan

+0

мой вопрос в том, почему адрес получить нулевое значение ...... когда им отправить его – Tufan

ответ

0

В моем приложении я использую этот код, чтобы получить адрес ... !!! Это для вашей справки.

Geocoder geocoder; 
    List<Address> addresses; 
    double latitude, longitude; 
    String zip, city, state, country; 
    googleMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() { 

       @Override 
       public void onMapLongClick(LatLng arg0) { 

        latitude = arg0.latitude; 
        longitude = arg0.longitude; 
        String title = ""; 
        geocoder = new Geocoder(MainActivity.this, Locale.getDefault()); 
        try { 
         addresses = geocoder.getFromLocation(latitude, longitude, 1); 
         if (addresses != null && addresses.size() > 0) { 
          zip = addresses.get(0).getPostalCode(); 
          city = addresses.get(0).getLocality(); 
          state = addresses.get(0).getAdminArea(); 
          country = addresses.get(0).getCountryName(); 
          if (zip != null) { 
           title += zip + ","; 
          } 
          if (city != null) { 
           title += city + ","; 
          } 
          if (state != null) { 
           title += state + ","; 
          } 
          if (country != null) { 
           title += country; 
          } 
         } else { 
          title = "Unknown Location"; 
          showPosition.setText("Address Not Found"); 
         } 

        } catch (IOException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
        } 
    // This will put marker and set Address as a marker title 
        googleMap.addMarker(new MarkerOptions().position(arg0).title(title)); 


       } 
      }); 


как установить маркер на карте Google?

MarkerOptions options = new MarkerOptions().position(latLng).title(shortDescStr); 
       googleMap.addMarker(options); 
+0

Я знаю, что это может быть правильно, но это доцент помогает мне, потому что я хочу установить маркер по умолчанию. Исходя из значения json и перейдите к Geocoder – Tufan

+0

, но почему адреса возвращают нулевое значение ..... я отправляю значение defalut из нового GeocoderTask (MainActivityMap.this) .execute (location); и в местоположении i задано значение по умолчанию – Tufan