2012-05-03 3 views
0
나는 내가 그것을 자동으로 경도를 얻을 것이다 latitude.Here 내가이 가능이 코드에서 위치를 얻기

주소에서 경도와 위도를 어떻게 얻을 수 있습니까?

coder = new Geocoder(this); 
try { 
    String locationName ="Gulshan 1"; 

     List<Address> addressList = coder.getFromLocationName(
       locationName, 5); 
     if (addressList != null && addressList.size() > 0) { 
      destLat = (int) (addressList.get(0).getLatitude() * 1e6); 
      destLon = (int) (addressList.get(0).getLongitude() * 1e6); 

      TextView pozycja = (TextView) findViewById(R.id.position); 
      pozycja.setText("lat: " 
        + addressList.get(0).getLatitude() + " lng: " 
        + addressList.get(0).getLongitude()); 
    } 
} 
catch (Exception e) { 
    Log.e("error", e.getMessage().toString()); 
} 

코드 시도하는 모든 주소를 입력 내 Google지도를 구현해야

?

+0

당신이 얻을 무엇을 기술 해주십시오 : 등 "아무것도", 쓰레기, 오류 메시지, – Irfy

+0

를 그것은 "0.0, 0.0을 찾을 수 없습니다"이 표시 :( –

답변

2

아래 코드를 사용하면 효과가 있습니다. FNE 작업 주어진 주소

Geocoder coder = new Geocoder(this); 
    List<Address> address = coder.getFromLocationName(
               "your address", 5); 
             if (address == null) 
              Log.d(TAG, 
                "Latitude and longitude not found"); 
             else { 
              Address location = address.get(0); 
              latitude = location.getLatitude(); 
              longitude = location.getLongitude(); 
             } 
+0

주소를 주소. 나는 그것을 이해할 수 없다. 왜 주소의 두 번? –

+0

미안 해요 내 실수는 내가 편집합니다 .. 감사합니다 ...... ... msid –

0

이것을 볼 수 있습니다. 이것은 어떻게 정보를 변환했는지입니다.

// getLatLon ("Gulshan-1", "Dhaka");

private void getLatLon(String loc,String div) { 
     Address addr = null; 
     try { 
      List<Address> addresses = new Geocoder(DataScrapper.this, Locale 
        .getDefault()).getFromLocationName(loc + " " + div 
        + " Bangladesh", 1); 

      if (!addresses.isEmpty()) { 
       addr = addresses.get(0); 

      } else 
       addr = null; 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     // addr.getLatitude(); 
    } 
+0

내가 DataScrapper의 새로운 클래스를 만들 필요가 있는가 –

+0

? 죄송합니다 .... 현재 클래스의 참조 만 해당 – Rasel

0
public double[] getGeoCodesFromAddress(String pLocationAddress) { 
     try { 

      cLocationGeneratorProp = new LocationGeneratorProp(); 
      objGeoCoder = new Geocoder(vContext, Locale.getDefault()); 
      vListAddress = objGeoCoder.getFromLocationName(pLocationAddress, 1); 
      if (vListAddress != null) { 
       latlong = new double[2]; 
       latlong[0] = vListAddress.get(0).getLatitude(); 
       latlong[1] = vListAddress.get(0).getLongitude(); 
      } 

     } catch (Exception e) { 
      Log.e("getGeoCodesFromAddress()", e.getMessage().toString()); 

     } 
     return latlong; 
    } 

LocationGeneratorProp

public class LocationGeneratorProp { 
    private String postalcode; 
    private String countryname; 
    private String countrycode; 
    private String fulladdress; 
    private String locationtype; 
    private double locationLat; 
    private double locationLong; 
    private double fromlocationlatitude; 
    private double fromlocationlongitude; 
    private double destinationlocationlatitude; 
    private double destinationlocationlongitude; 

    public String getPostalcode() { 
     return postalcode; 
    } 

    /** 
    * @param postalcode 
    *   Postal Code Of the Adrress 
    */ 
    public void setPostalcode(String postalcode) { 
     this.postalcode = postalcode; 
    } 

    /** 
    * @return String CountryName 
    * 
    */ 
    public String getCountryname() { 
     return countryname; 
    } 

    public void setCountryname(String countryname) { 
     this.countryname = countryname; 
    } 

    public String getCountrycode() { 
     return countrycode; 
    } 

    public void setCountrycode(String countrycode) { 
     this.countrycode = countrycode; 
    } 

    public String getFulladdress() { 
     return fulladdress; 
    } 

    public void setFulladdress(String fulladdress) { 
     this.fulladdress = fulladdress; 
    } 

    public String getLocationtype() { 
     return locationtype; 
    } 

    public void setLocationtype(String locationtype) { 
     this.locationtype = locationtype; 
    } 

    public double getLocationLat() { 
     return locationLat; 
    } 

    public void setLocationLat(double locationLat) { 
     this.locationLat = locationLat; 
    } 

    public double getLocationLong() { 
     return locationLong; 
    } 

    public void setLocationLong(double locationLong) { 
     this.locationLong = locationLong; 
    } 

    public double getFromlocationlatitude() { 
     return fromlocationlatitude; 
    } 

    public void setFromlocationlatitude(double fromlocationlatitude) { 
     this.fromlocationlatitude = fromlocationlatitude; 
    } 

    public double getFromlocationlongitude() { 
     return fromlocationlongitude; 
    } 

    public void setFromlocationlongitude(double fromlocationlongitude) { 
     this.fromlocationlongitude = fromlocationlongitude; 
    } 

    public double getDestinationlocationlatitude() { 
     return destinationlocationlatitude; 
    } 

    public void setDestinationlocationlatitude(
      double destinationlocationlatitude) { 
     this.destinationlocationlatitude = destinationlocationlatitude; 
    } 

    public double getDestinationlocationlongitude() { 
     return destinationlocationlongitude; 
    } 

    public void setDestinationlocationlongitude(
      double destinationlocationlongitude) { 
     this.destinationlocationlongitude = destinationlocationlongitude; 
    } 

} 

JST 테스트 THS 코드 나 KNW 할 수있는 경우 prob..with의 THS

다음 코드로
1

이동합니다

List<Address> addressList = coder.getFromLocationName(locationName, 1); 
Address addr=addressList.get(0); 
destLat=addr.getLatitude(); 
destLon =addr..getLongitude(); 
TextView pozycja = (TextView) findViewById(R.id.position); 
      pozycja.setText("lat: "+destLat+ " lng: "+destLon); 
0

아래 코드를 사용하면 모든 주소 (도시, 직업, 국가)에서 위도와 경도를 쉽게 얻을 수 있습니다.

 public void getlatd() 

    {   
     String add=txt_add.getText().toString();//address of location u have entered 
     Toast.makeText(this, "Your add is : "+add, Toast.LENGTH_LONG).show(); 
    final Geocoder geocoder = new Geocoder(this);  
    try { 

     List<Address> addresses = geocoder.getFromLocationName(add, 1); 

     if (addresses != null && !addresses.isEmpty()) { 

     Address address = addresses.get(0); 

     txt.setText("latitude and longtd is :"+address.getLatitude()+"\n"+address.getLongitude()); 
     } 
    else { 
      Toast.makeText(this, "NO latd and longtd for this add", Toast.LENGTH_LONG).show(); 
     } 
    } 
    catch (IOException e) { 
     Toast.makeText(this, "Error :"+e.getMessage(), Toast.LENGTH_LONG).show(); 
    } 
} 


        "Robo-Techi" 
관련 문제