2014-04-20 5 views
3

그래서 내 앱에서 Google지도 api를 사용하고 있으며 지오 코딩을 사용하여 사용자의 현재 위치를 기반으로 주소를 결정합니다. 지오 코더 (Geocoder) Android 클래스를 사용하고 있었지만 정말 끔찍하게 작동한다는 것을 알았습니다. 그것은 단지 신뢰할 수 없습니다. 그래서 저는 여기에서 보았던 게시물을 사용하여 내 지오 코더를 만들었습니다. 문제는, 지금 내가 서버 측 또는 클라이언트 측 지오 코딩을 사용하고 있는지 여부를 알 수 없습니다. 하나는 제한이 있고 다른 하나는 실제로는 그렇지 않기 때문에 이것은 중요합니다. 내 코드는 모두 Android에 있습니다.안드로이드 : 클라이언트 측 또는 서버 측 지오 코딩을하고 있습니까?

public List<Address> getFromLocation(double latitude, double longitude, 
     int maxResults) throws IOException, LimitExceededException { 
    if (latitude < -90.0 || latitude > 90.0) { 
     throw new IllegalArgumentException("latitude == " + latitude); 
    } 
    if (longitude < -180.0 || longitude > 180.0) { 
     throw new IllegalArgumentException("longitude == " + longitude); 
    } 

    if (isLimitExceeded(context)) { 
     throw new LimitExceededException(); 
    } 

    final List<Address> results = new ArrayList<Address>(); 

    final StringBuilder url = new StringBuilder(
      "http://maps.googleapis.com/maps/api/geocode/json?sensor=true&latlng="); 
    url.append(latitude); 
    url.append(','); 
    url.append(longitude); 
    url.append("&language="); 
    url.append(Locale.getDefault().getLanguage()); 

    HttpClient httpclient = new DefaultHttpClient(); 
    HttpPost httppost = new HttpPost(url.toString()); 

    try { 
     HttpResponse response = httpclient.execute(httppost); 
     String jsonResult = inputStreamToString(
       response.getEntity().getContent()).toString(); 

     Gson gson = new Gson(); 
     MyGeocodeResponse geocodeResponse = gson.fromJson(jsonResult, MyGeocodeResponse.class); 
     final Address current = new Address(Locale.getDefault()); 
     if(geocodeResponse.getStatus().equals(STATUS_OK)) { 
      MyGeocode locGeocode= geocodeResponse.getResults().get(0); 
      String streetAddress = ""; 
      for(MyAddressComponent component : locGeocode.getAddress_components()) { 
       for(String type : component.getTypes()) { 
        if(type.equals("locality")) { 
         current.setLocality(component.getLong_name()); 
        } 

        if(type.equals("administrative_area_level_1")) { 
         current.setAdminArea(component.getLong_name()); 
        } 

        if(type.equals("street_number")) { 
         if(streetAddress.length() != 0) { 
          current.setAddressLine(0, component.getLong_name() + " " + streetAddress); 
         } else { 
          streetAddress = component.getLong_name(); 
         } 
        } 

        if(type.equals("route")) { 
         if(streetAddress.length() != 0) { 
          current.setAddressLine(0, streetAddress + " " + component.getShort_name()); 
         } else { 
          streetAddress = component.getShort_name(); 
         } 
        } 
       } 
      } 
      current.setLatitude(latitude); 
      current.setLongitude(longitude); 
      results.add(current); 
     } 


     Log.i("TEST", "Got it"); 

    } catch (ClientProtocolException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    return results; 
} 

편집 : 여기

이 내 "MyGeocoder"클래스 내에, 일부 코드의 그리고이 다음 수이 코드는 서버 측 지오 코딩 경우 I이며, 추가 질문을 추측 하루에 2,500 번 실행하거나 앱 사용자 당 하루 2,500 번 실행할 수 있습니까? 첫 번째 옵션 인 경우 여전히 괜찮습니다.하지만 두 번째 옵션 인 경우 중간 사용자가 절반 밖에되지 않으려는 앱의 경우 서버 쪽 지오 코딩을 사용하여 그 한도를 초과하지 않는 방법을 알 수 없습니다.

답변

1

난 당신의 코드는 http://maps.googleapis.com/maps/api/geocode/json?sensor=true&latlng=을 썼다을 찾고 후

지오 코딩 서버 측 또는 클라이언트 측을 사용하고 있다면 지금은 모르는, 그래서 당신은 지오 코딩을 호출로 서버 사이드 역 지오 코딩입니다 외부 http 호출을 추가하여

이 코드가 서버 측 지오 코딩 인 경우이 코드는 하루에 2,500 번만 실행하거나 앱 사용자 당 하루 2,500 번만 실행할 수 있습니까?

2,500 요청 제한은 IP 주소 당입니다 (기본적으로 하루 2500 요청을 언급 함).이 코드는 모든 사용자에 대해 하루 2,500 회만 실행됩니다. 한 가지 명심해야 할 것은 http 또는 geocoder API 호출을 사용하면 서버 또는 클라이언트에서이 호출을 수행하는 위치가 중요하지 않습니다.

google link에는 "클라이언트 측 지오 코딩 사용시기"및 "서버 측 지오 코딩 사용시기"가 있습니다.

+0

그래서 @ app3523641, 내 앱이 누군가 내 앱을 열 때마다 이것을 호출하면이 코드는 하루에 2,500 번만 작동합니까? 또는 사용자 당 2,500 번 작동합니까? IP 주소 기반이기 때문에 ... 이것은 내 서버가 아니라 내 Android 앱 코드에서 호출됩니다. – user1513171

+0

답장을 보내 드려 죄송합니다. 예, 혼란 스러웠습니다. 좋은 채널 파트너에게이 질문을 던졌고, 폼 모바일을 사용하거나 웹 클라이언트 서버에서 똑같은 대답을하니 대답이 혼란 스러웠습니다. T는 어떤 명확성을 줄 수 있도록 Google 개발자 팀에이 질문을했습니다. 그들은 무엇을 말해야하는지 봅시다. – Dev

+0

android와 함께해야 할 때를 의미합니다. 위치. 더 자세한 내용을 보려면 링크 아래에 제한 방문이없는 지오 코더 http://stackoverflow.com/questions/24186388/google-maps-mobile-sdk-for-business-vs-google-maps-android-api/24189953#24189953 – Dev

관련 문제