我是android的新手...我已经在arcGIS地图上工作了2天,在arcGIS地图上显示多个引脚..我只是在调试而不是运行时才输出..我必须显示弹出窗口(标注)whren贴在pin.Please一些身体帮助我..谢谢提前..
这是我的代码
if (MyXMLHandler.getResponse().getLatitude().size() > 0) {
for (int i = 0; i < MyXMLHandler.getResponse().getLatitude()
.size(); i++) {
Log.v("TEST", "size=="
+ MyXMLHandler.getResponse().getLatitude().size());
double latitude = Double.parseDouble(MyXMLHandler
.getResponse().getLatitude().get(i).toString());
double langtude = Double.parseDouble(MyXMLHandler
.getResponse().getLongtude().get(i).toString());
Log.v("TEST", "lan........" + latitude + "....lng......"
+ langtude);
latlong = new Point(langtude, latitude);
point = (Point) GeometryEngine.project(latlong,
SpatialReference.create(4326),
mMapView.getSpatialReference());
gLayer = new GraphicsLayer();
PictureMarkerSymbol pictureMarkerSymbol = new PictureMarkerSymbol(
getResources().getDrawable(R.drawable.s));
graphic = new Graphic(point, pictureMarkerSymbol);
gLayer.addGraphic(graphic);
mMapView.addLayer(gLayer);
mMapView.setOnSingleTapListener(Arcgis_routeActivity.this);
}
@Override
public void onSingleTap(final float x, final float y) {
// TODO Auto-generated method stub
LayoutInflater inflator = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.callout_xml, null);
TextView textView1 = (TextView) v.findViewById(R.id.textView1);
textView1.setText(MyXMLHandler.getResponse().getName().get(0)
.toString());
location = new Point(x, y);
if (callout != null) {
callout.hide();
} else {
callout = mMapView.getCallout();
callout.setStyle(R.xml.calloutstyle);
}
callout.setOffset(0, -15);
callout.show(location, v);
}``
答案 0 :(得分:0)
Iam displaying multiple pins in asynctask from the raw folder..on single tap listener comparig the tapped listener lat long values with the dropped pin lat longs..
private class LocationsDisplaying extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
/** Handling XML */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
/** Create handler to handle XML Tags ( extends DefaultHandler ) */
MyXMLHandler myXMLHandler = new MyXMLHandler();
xr.setContentHandler(myXMLHandler);
InputStream is = MainActivity.this.getResources()
.openRawResource(R.raw.service);
xr.parse(new InputSource(is));
} catch (Exception e) {
System.out.println("XML Pasing Excpetion = " + e);
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
dialog.dismiss();
new PinDisplay().execute();
}
}
class PinDisplay扩展AsyncTask { ProgressDialog对话框;
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
dialog = new ProgressDialog(MainActivity.this);
dialog.setTitle("Please wait...");
dialog.setCanceledOnTouchOutside(false);
dialog.setMessage("Loading......");
dialog.show();
}
@Override
protected Void doInBackground(Void... params) {
displaying_mapUI();
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
dialog.dismiss();
}
}
private void displaying_mapUI() {
// TODO Auto-generated method stub
Point latlong = null;
Point point;
Graphic graphic;
GraphicsLayer gLayer;
if (MyXMLHandler.getResponse().getLatitude().size() > 0) {
for (int i = 0; i < MyXMLHandler.getResponse().getLatitude().size(); i++) {
Log.v("TEST", "size=="
+ MyXMLHandler.getResponse().getLatitude().size());
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
double latitude = Double.parseDouble(MyXMLHandler.getResponse()
.getLatitude().get(i).toString());
double langtude = Double.parseDouble(MyXMLHandler.getResponse()
.getLongtude().get(i).toString());
Log.v("TEST", "lan........" + latitude + "....lng......"
+ langtude);
latlong = new Point(langtude, latitude);
point = (Point) GeometryEngine.project(latlong,
SpatialReference.create(4326),
mMapView.getSpatialReference());
gLayer = new GraphicsLayer();
PictureMarkerSymbol pictureMarkerSymbol = new PictureMarkerSymbol(
getResources().getDrawable(R.drawable.pushpin2));
graphic = new Graphic(point, pictureMarkerSymbol);
gLayer.addGraphic(graphic);
mMapView.addLayer(gLayer);
}
}
}
@Override
public void onSingleTap(final float x, final float y) {
// TODO Auto-generated method stub
mMapView.setRotationAngle(0);
compass.setRotationAngle(mMapView.getRotationAngle());
compass.postInvalidate();
LayoutInflater inflator = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflator.inflate(R.layout.callout_xml, null);
TextView text = (TextView) view.findViewById(R.id.textView1);
// View view = createView();
Point p = mMapView.toMapPoint(x, y);
// Log.v("TEST", "X=" + p.getX());
// Log.v("TEST", "Y=" + p.getY());
SpatialReference sp = SpatialReference.create(4326);
Point aux = (Point) GeometryEngine.project(p,
mMapView.getSpatialReference(), sp);
location = new Point(aux.getX(), aux.getY());
StringTokenizer tokenst1 = new StringTokenizer(String.valueOf(aux
.getY()), ".");
String firstt1 = tokenst1.nextToken();
float tapLat = Float.parseFloat(firstt1);
StringTokenizer tokenst2 = new StringTokenizer(String.valueOf(aux
.getX()), ".");
String firstt2 = tokenst2.nextToken();
float tapLng = Float.parseFloat(firstt2);
StringTokenizer tokensl1 = new StringTokenizer(String.valueOf(latlong
.getY()), ".");
String firstl1 = tokensl1.nextToken();
float staticLat = Float.parseFloat(firstl1);
StringTokenizer tokensl2 = new StringTokenizer(String.valueOf(latlong
.getX()), ".");
String firstl2 = tokensl2.nextToken();
float staticLng = Float.parseFloat(firstl2);
Log.v("TEST", "tapLat" + tapLat);
Log.v("TEST", "tapLng" + tapLng);
Log.v("TEST", "staticLat" + staticLat);
Log.v("TEST", "staticLng" + staticLng);
if (tapLat == staticLat && tapLng == staticLng) {
locationName = "Alberta";
} else {
for (int j = 0; j < MyXMLHandler.getResponse().getLatitude().size(); j++) {
double double_lat = MyXMLHandler.getResponse().getLatitude().get(j);
double double_long = MyXMLHandler.getResponse().getLongtude().get(j);
StringTokenizer tokens = new StringTokenizer(String.valueOf(double_lat),
".");
String first = tokens.nextToken();
Log.v("TEST", "first......" + first);
StringTokenizer tokens1 = new StringTokenizer(
String.valueOf(double_long), ".");
String first1 = tokens1.nextToken();
Log.v("TEST", "first1111111......" + first1);
float service_location_lat = Float.parseFloat(first);
float service_location_lng = Float.parseFloat(first1);
if (tapLat == service_location_lat
&& tapLng == service_location_lng) {
Log.v("TEST", "if service_location_lng....."
+ service_location_lng);
Log.v("TEST", "if service_location_lat........"
+ service_location_lat);
locationName = MyXMLHandler.getResponse().getName().get(j)
.toString().trim();
Log.v("TESt", "locationName....." + locationName);
j = MyXMLHandler.getResponse().getLatitude().size();
} else {
locationName = "No Results Found";
}
}
}
text.setText(locationName);
callout.show(p, view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (locationName.equalsIgnoreCase("No Results Found")
|| locationName.equalsIgnoreCase("Alberta")) {
Toast.makeText(getApplicationContext(),
"Please select Location", Toast.LENGTH_SHORT)
.show();
} else {
Intent intent = new Intent(MainActivity.this,
RouteDisplying.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
});
}
答案 1 :(得分:0)
这是我发现可能有帮助的calloutPopupWindow。遗憾的是我还没有使用它,但是在API中它提到它类似于callout,并且具有能够有多个标注的额外好处。 希望这有帮助!