나는 안드로이드 프로그래밍에 익숙하지 않아서이 앱을 개발하여 안드로이드 폰에서 Google지도 서비스를 호출하고 웹 서비스에 액세스하여 위도와 경도 값을 검색합니다. 지도에 그려야 할 방송국.프로그램이 응답 속도가 매우 느림 [Google Api]
Foll이 코드입니다.하지만 앱을 실행할 때 프로그램이 반응이 없으므로 하나의 annotation과 tht도 패닝 및 확대/축소 이벤트가 정말 느리고 때로는 코드가 멈추는 경우가 있습니다.
해결 방법을 찾으십시오.
DemoOverlay.java
public class DemoOverlay extends Overlay
{
ArrayList<String> arrlat_long = new ArrayList<String>();
public static String str;
public static String str1;
String responseBody;
int n=0;
String Url = "http://hiscentral.cuahsi.org/webservices/hiscentral.asmx/GetSeriesCatalogForBox2";
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5);
HttpClient httpclient = new DefaultHttpClient();
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow)
{
super.draw(canvas, mapView, shadow);
Projection projection = mapView.getProjection();
if(!Url.endsWith("?"))
{
Url += "?";
}
int latSpan = mapView.getLatitudeSpan();
int lngSpan = mapView.getLongitudeSpan();
GeoPoint mapCenter = mapView.getMapCenter();
int mapLeftGeo = mapCenter.getLongitudeE6() - (lngSpan/2);
int mapRightGeo = mapCenter.getLongitudeE6() + (lngSpan/2);
int mapTopGeo = mapCenter.getLatitudeE6() - (latSpan/2);
int mapBottomGeo = mapCenter.getLatitudeE6() + (latSpan/2);
GeoPoint geoPoint = this.getSampleLocation();
nameValuePairs.add(new BasicNameValuePair("xmin", "-100"));
nameValuePairs.add(new BasicNameValuePair("xmax", "-90"));
nameValuePairs.add(new BasicNameValuePair("ymin", "40"));
nameValuePairs.add(new BasicNameValuePair("ymax", "55"));
nameValuePairs.add(new BasicNameValuePair("networkIDs", ""));
nameValuePairs.add(new BasicNameValuePair("conceptKeyword", "precipitation"));
nameValuePairs.add(new BasicNameValuePair("beginDate", "1/1/2009"));
nameValuePairs.add(new BasicNameValuePair("endDate", "1/1/2010"));
String paramString = URLEncodedUtils.format(nameValuePairs, "utf-8");
Url += paramString;
if ((geoPoint.getLatitudeE6() > mapTopGeo && geoPoint.getLatitudeE6() < mapBottomGeo)
&& (geoPoint.getLongitudeE6() > mapLeftGeo && geoPoint.getLongitudeE6() < mapRightGeo))
{
geoPoint = arrlat_long(n);
Point myPoint = new Point();
projection.toPixels(geoPoint, myPoint);
Bitmap marker = BitmapFactory.decodeResource(mapView.getContext().getResources(), R.drawable.markerblue);
canvas.drawBitmap(marker, myPoint.x - 15, myPoint.y - 30, null);
}
}
private GeoPoint getSampleLocation()
{
GeoPoint sampleGeoPoint;
// int n=0;
try {
HttpPost httppost = new HttpPost(Url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
responseBody = EntityUtils.toString(response.getEntity());
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setValidating(false);
XmlPullParser myxml = factory.newPullParser();
InputStream raw = new ByteArrayInputStream(responseBody.getBytes());
myxml.setInput(raw, null);
int eventType = myxml.getEventType();
while(eventType != XmlPullParser.END_DOCUMENT)
{
if(eventType == XmlPullParser.START_DOCUMENT)
{
Log.d("ParseXmlActivity", "In start document");
}
else if(eventType == XmlPullParser.START_TAG)
{
if (myxml.getName().equals("latitude"))
{
str="";
str += "Lat:" + myxml.nextText().toString();
Log.d("ParseXmlActivity", "In start tag = "+str);
arrlat_long.add(str);
}
if (myxml.getName().equals("longitude"))
{
str1 += "--Lon:" + myxml.nextText().toString();
Log.d("ParseXmlActivity", "In start tag = "+str1);
arrlat_long.add(str1);
}
}
eventType = myxml.next();
}
}
catch (XmlPullParserException e)
{
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
int in =Integer.parseInt(str);
int in1 =Integer.parseInt(str1);
sampleGeoPoint = new GeoPoint(in,in1);
return sampleGeoPoint;
}}
에 대한 재미있다! –
내 코드에서 AsyncTask를 사용하는 법을 말해 줄 수 있습니까? –
미안하지만, 나는 당신이 성취하려는 것을 완전히 이해하지 못하기 때문에 그렇게 할 수 없습니다. 어쩌면 당신은 AsyncTask조차 필요하지 않습니다. 귀하의 서비스가 위치의 범위에 따라 많은 아이콘을 다운로드한다면, 나는 전화의 위치 (특정 기수)에 근거하여 한 번 다운로드하여 함께 추가 할 것입니다. 당신이하려고하는 것을 더 분명히해야합니다. –