Google 정적지도를 검색하는 AsyncTask에 전달되는 주소에서 경도/위도를 가져와야하는 문제가 있습니다.Google 정적지도를 사용하여 경도/위도 검색 문제
이 AsyncTask는 좌표 집합을 가져 와서지도를 만들 수 있으며 Google Places API를 사용하여 검색 한 주소를 사용할 수도 있습니다.
내가 겪고있는 문제는 전달 된 주소의 좌표를 검색하는 방법을 모르겠다는 것입니다. 누구든지 Long/Lat를 얻을 수있는 방법을 알고 있습니까? 내가 그것을하는 방법을 알아 낸 유일한 방법은 다른 AsyncTask를 사용하는 것이다. 나는 2 개의 요청을하지는 않을 것이다.
는 정적지도를 클래스 CreateStaticMapAsyncTask를 생성하는 AsyncTask를 확장 {
private static final String STATIC_MAPS_API_BASE = "https://maps.googleapis.com/maps/api/staticmap";
private static final String STATIC_MAPS_API_SIZE = "300x300";
@Override
protected void onPreExecute() {
addTask(); // adds one to task count.
super.onPreExecute();
}
@Override
protected Bitmap doInBackground(String... params) {
// TODO Auto-generated method stub
locationString = params[0];
Log.e("LOCATION STRING", locationString);
Bitmap bmp = null;
StringBuilder sb = new StringBuilder(STATIC_MAPS_API_BASE);
try {
sb.append("?center=").append(
URLEncoder.encode(locationString, "UTF-8"));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
sb.append("&size=" + STATIC_MAPS_API_SIZE);
sb.append("&key=" + API_KEY);
String url = new String(sb.toString());
Log.e("URL", sb.toString());
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
InputStream in = null;
try {
in = httpclient.execute(request).getEntity().getContent();
bmp = BitmapFactory.decodeStream(in);
in.close();
} catch (Exception e) {
e.printStackTrace();
}
return bmp;
}
protected void onPostExecute(Bitmap bmp) {
super.onPostExecute(bmp);
if (bmp != null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
data = stream.toByteArray();
removeTask();
// allTasksComplete();
}
}
}