이하입니다. 이
String url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?rankby=distance&types=meal_takeaway&sensor=true&key=API_KEY&location=" + coords.getLat() + "," + coords.getLng();
당신은 단순히 매개 변수를 삽입하고 있습니다 : coords
을 가정하는 가장 쉬운이 같은 것
는, 그것의 방법은 좌표를 반환하여 LatLng를 변수 getLat()
및 getLng()
의 이름입니다입니다 . 더 시원한 작업을 원할 경우 LatLng 객체의 toString() 메서드를 재정 의하여 좌표를 올바른 형식으로 반환 할 수 있습니다. 예 : 그렇게 할 이유
String url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?rankby=distance&types=meal_takeaway&sensor=true&key=API_KEY&location=" + coords.toString();
:
@Override
public String toString(){
return getLat() + "," + getLng();
}
은 우리가의 라인을 따라 뭔가 초기 URL을 변경할 수 있도록 할거야? 여러 가지 이유가 있습니다. 조금 더 깔끔하고, 조금 더 OO 기반으로되어 있습니다. 당신은 아마 당신의 문자열 리소스에 저장 한 API 키를 삽입에 관해서는
, 당신은 매우 비슷한 할 것입니다 : 당신이 거기에 자원을 얻기 위해 상황에 어떤 종류의 필요가 명확하게
String url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?rankby=distance&types=meal_takeaway&sensor=true&key=" + context.getResources().getString(R.string.your_api_key) + "&location=" + coords.toString();
을, 하지만 그게 가능해야합니다. 그냥 다른 방법을 보여줍니다.