好吧,我编写了这段代码,允许用户平移谷歌地图,选择一个区域,然后当他/她按下按钮时,角落的坐标被传递给一个 web 服务,该服务返回该区域内的注释并将其绘制在地图。
该应用程序在所选区域内运行良好。现在我想添加一个功能,在单击注释时,它会向我返回这些值的图表。
可以从下面的网络服务访问此图,
http://hydrodata.info/graph/handler2.ashx?startDate=2010-10-01&endDate=2011-08-01&siteCode=NWISDV:13073000&variableCode=NWISDV:00060&serviceUrl=http://river.sdsc.edu/wateroneflow/NWIS/DailyValues.asmx?WSDL&height=500&width=500
站点代码、变量代码等是从我随身携带的另一个网络服务中获得的。
那么任何人都可以帮助我如何在我的应用程序上显示此图表吗?
下面附上代码,
主要课程是,
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapController = mapView.getController();
mapController.setZoom(8);
addListenerOnButton();
}
public void addListenerOnButton()
{
final MapView mapView;
mapView = (MapView) findViewById(R.id.mapview);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener()
{
MapView mapView;
public void onClick(View v)
{
public void onClick(View v)
{
List<Overlay> mapOverlays = mapView.getOverlays();
for(int i=0;i<mapOverlays.size();i++)
{
mapOverlays.remove(0);
}
//mapView.getOverlays().clear(); //from here
Drawable drawable = AndroidTestActivity.this.getResources().getDrawable(R.drawable.mapmarker);
HelloItemizedOverlay itemizedoverlay1= new HelloItemizedOverlay(drawable,AndroidTestActivity.this);
itemizedoverlay1.delOverlay();
if(!mapOverlays.isEmpty())
{
mapOverlays.clear();
mapView.invalidate();
}
EditText text = (EditText)findViewById(R.id.editText1);
String parameter= text.getText().toString();
EditText text2 = (EditText)findViewById(R.id.editText2);
String strdd=text2.getText().toString();
EditText textmm2 = (EditText)findViewById(R.id.editText23);
String strmm=textmm2.getText().toString();
EditText textyy2 = (EditText)findViewById(R.id.editText24);
String stryy=textyy2.getText().toString();
String startDate=strdd+"/"+ strmm+"/"+ stryy;
EditText textedd2 = (EditText)findViewById(R.id.editText35);
String stredd=textedd2.getText().toString();
EditText textemm2 = (EditText)findViewById(R.id.editText36);
String stremm=textemm2.getText().toString();
EditText texteyy2 = (EditText)findViewById(R.id.editText37);
String streyy=texteyy2.getText().toString();
String endDate= stredd+"/"+ stremm+"/"+ streyy;
GeoPoint center = mapView.getMapCenter();
float centerLatitude = (float)(center.getLatitudeE6())/1000000;
float centerLongitude = (float)(center.getLongitudeE6())/1000000;
GeoPoint mapTopLeft = mapView.getProjection().fromPixels(0,0);
topLatitude = (double)(mapTopLeft.getLatitudeE6())/1000000;
leftLongitude = (double)(mapTopLeft.getLongitudeE6())/1000000;
GeoPoint mapBottomRight= mapView.getProjection().fromPixels(width, height/2);
bottomLatitude = (double)(mapBottomRight.getLatitudeE6())/1000000;
rightLongitude = (double)(mapBottomRight.getLongitudeE6())/1000000;
str= Double.toString(centerLatitude);
str1=Double.toString(centerLongitude);
OverlayItem overlayitem = new OverlayItem(center, str, "center");
itemizedoverlay1.addOverlay(overlayitem);
str2= Double.toString(topLatitude);
str3=Double.toString(leftLongitude);
OverlayItem overlayitem1 = new OverlayItem(mapTopLeft, str2, "topLeft");
itemizedoverlay1.addOverlay(overlayitem1);
str4= Double.toString(bottomLatitude);
str5=Double.toString(rightLongitude);
OverlayItem overlayitem2 = new OverlayItem(mapBottomRight, str4, "bottomRight");
itemizedoverlay1.addOverlay(overlayitem2);
mapOverlays.add(itemizedoverlay1);
dms=Double.toString(topLatitude)+";"+Double.toString(leftLongitude)+";"+Double.toString(bottomLatitude)+";"+Double.toString(rightLongitude);
String[] arr=dms.split(";");
for (int i=0; i<4 ; i++)
{
double value = Double.valueOf(arr[i]);
if (value <0)
{
value=value*-1;
int y = (int) value;
double rest= value - y;
String min_sec = Double.toString(rest);
String min = min_sec.substring(2,4); /* minutes */
String sec = min_sec.substring(4,6); /* seconds */
minutes = (Double.valueOf(min)) / 60; /* minutes DD */
seconds = Double.valueOf(sec) / 3600;
double value1= y + minutes + seconds;
value1=value1*-1;
strtest=strtest+Double.toString(value1)+";";
// pass[i]= value1;
}
else
{
int y1 = (int) value;
double rest1= value - y1;
String min_sec1 = Double.toString(rest1);
String min1 = min_sec1.substring(2,4); /* minutes */
String sec1 = min_sec1.substring(4,6); /* seconds */
minutes = (Double.valueOf(min1)) / 60; /* minutes DD */
seconds = Double.valueOf(sec1) / 3600;
double value1= y1 + minutes + seconds;
strtest=strtest+Double.toString(value1)+";";
// pass[i]= value1;
}
}
strtest=Double.toString(a)+";"+Double.toString(b)+";"+Double.toString(c)+";"+Double.toString(d)+";"+parameter +";"+startDate+";"+endDate;
Log.d("strtest strtest", "strtest strtest = "+strtest);
Intent msgIntent = new Intent(AndroidTestActivity.this,Intentservice.class);
msgIntent.putExtra("strtest", strtest); //arrlat_long
startService(msgIntent);
//Dynamic registration Receiver
IntentFilter filter = new IntentFilter(ACTION_RECV_MSG);
filter.addCategory(Intent.CATEGORY_DEFAULT);
receiver = new MessageReceiver();
registerReceiver(receiver, filter);
IntentFilter filter2 = new IntentFilter(ACTION_OTHER_MSG);
filter2.addCategory(Intent.CATEGORY_DEFAULT);
receiver = new MessageReceiver();
registerReceiver(receiver, filter2);
} }
);
}
//Broadcast to receive
public class MessageReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "hello",Toast.LENGTH_SHORT).show();
if(arrlat_lat!= null)
{
arrlat_lat.clear();
}
if(arrlat_long!= null) //!arrlat_long.isEmpty()
{
arrlat_long.clear();
}
arrlat_long = intent.getStringArrayListExtra("codnt");
arrlat_lat = intent.getStringArrayListExtra("codntlat");
// text.setText(message);
Toast.makeText(context, arrlat_long.get(0),Toast.LENGTH_SHORT).show();
testoverlay();
}
}
public void testoverlay()
{
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.mapmarker);
if (flag==0)
{
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);
for(int i=0;i<arrlat_long.size();i++)
{
float lat = Float.parseFloat(arrlat_lat.get(i));
float lng = Float.parseFloat(arrlat_long.get(i));
GeoPoint point = new GeoPoint((int)(lat * 1E6), (int)(lng * 1E6));
lat1= lat;
lon1= lng;
str= Double.toString(lat1);
str1=Double.toString(lon1);
OverlayItem overlayitem = new OverlayItem(point, str,str1);
itemizedoverlay.addOverlay(overlayitem);
}mapOverlays.add(itemizedoverlay);
mapView.invalidate();
flag++;
}
else
{
HelloItemizedOverlay itemizedoverlay12 = new HelloItemizedOverlay(drawable,this);
// mapView.getOverlays().clear();
for(int i=0;i<arrlat_long.size();i++)
{
float lat = Float.parseFloat(arrlat_lat.get(i));
float lng = Float.parseFloat(arrlat_long.get(i));
GeoPoint point = new GeoPoint((int)(lat * 1E6), (int)(lng * 1E6));
lat1= lat;
lon1= lng;
str= Double.toString(lat1);
str1=Double.toString(lon1);
OverlayItem overlayitem = new OverlayItem(point, str,str1);
itemizedoverlay12.addOverlay(overlayitem);
}mapOverlays.add(itemizedoverlay12);
mapView.invalidate();
} }
@Override
protected boolean isRouteDisplayed()
{
// TODO Auto-generated method stub
return false;
}
}
IntentService.java
public Intentservice()
{
super("Intentservice");
// TODO Auto-generated constructor stub
}
@Override
protected void onHandleIntent(Intent intent)
{
String strxmin,xmax,ymin,ymax,par,startDate,endDate;
String str=intent.getExtras().getString("strtest");
Log.d("onHandleIntent", "onHandleIntent onHandleIntent= "+str);
String[] arrtelog=str.split(";");
if(arrtelog.length >3)
{
strxmin=arrtelog[0];
xmax=arrtelog[1];
ymin=arrtelog[2];
ymax=arrtelog[3];
par=arrtelog[4];
startDate=arrtelog[5];
endDate=arrtelog[6];
Log.d("onHandleIntent", "onHandleIntent strxmin= "+strxmin);
Log.d("onHandleIntent", "onHandleIntent strxmin= "+xmax);
Log.d("onHandleIntent", "onHandleIntent strxmin= "+ymin);
Log.d("onHandleIntent", "onHandleIntent strxmin= "+ymax);
Log.d("onHandleIntent", "onHandleIntent strxmin= "+par);
Log.d("onHandleIntent", "onHandleIntent strxmin= "+startDate);
Log.d("onHandleIntent", "onHandleIntent strxmin= "+endDate);
// TODO Auto-generated method stub
HttpClient httpclient = new DefaultHttpClient();
String Url = "http://hiscentral.cuahsi.org/webservices/hiscentral_1_1.asmx/GetSeriesCatalogForBox2";
if(!Url.endsWith("?"))
{
Url += "?";
}
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5);
nameValuePairs.add(new BasicNameValuePair("xmin",xmax)); //ymax
nameValuePairs.add(new BasicNameValuePair("xmax",ymax)); //xmax
nameValuePairs.add(new BasicNameValuePair("ymin",ymin)); //strxmin
nameValuePairs.add(new BasicNameValuePair("ymax", strxmin)); //ymin
nameValuePairs.add(new BasicNameValuePair("networkIDs", ""));
nameValuePairs.add(new BasicNameValuePair("conceptKeyword", par));
nameValuePairs.add(new BasicNameValuePair("beginDate", startDate));
nameValuePairs.add(new BasicNameValuePair("endDate", endDate));
String paramString = URLEncodedUtils.format(nameValuePairs, "utf-8");
Url += paramString;
try
{
HttpPost httppost = new HttpPost(Url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity httpentity = response.getEntity();
if(httpentity == null)
{
}
else
{
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();
if(!arrlat_lat.isEmpty())
{
arrlat_lat.clear();
}
if(!arrlat_long.isEmpty()) //!arrlat_long.isEmpty(),, arrlat_long!= null
{
arrlat_long.clear();
}
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 = myxml.nextText().toString();
Log.d("ParseXmlActivity", "In start tag = "+str);
arrlat_lat.add(str);
}
if (myxml.getName().equals("longitude"))
{
str = myxml.nextText().toString();
Log.d("ParseXmlActivity", "In start tag = "+str);
arrlat_long.add(str);
}
}
eventType = myxml.next();
}
}
}
catch (XmlPullParserException e)
{
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch(IndexOutOfBoundsException e)
{
}
// IntentFilter filter = new IntentFilter(ACTION_RECV_MSG);
// filter.addCategory(Intent.CATEGORY_DEFAULT);
//receiver = new MessageReceiver();
// registerReceiver(receiver, filter);
if(arrlat_long.size()>0)
{
Log.d("TEST TESTTEST", "In start TESTTEST = "+arrlat_long.get(0)+" $$$ "+arrlat_long.size());
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(ACTION_RECV_MSG);
broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
broadcastIntent.putStringArrayListExtra("codnt", arrlat_long); //arrlat_long
broadcastIntent.putStringArrayListExtra("codntlat", arrlat_lat); //arrlat_lat
sendBroadcast(broadcastIntent);
}
}
}
}