我正在做毕业论文,我必须做一个Android应用程序,显示我在谷歌地图上的位置(我做过的事情),当我点击大学里的一些针脚会弹出一些建筑物的信息,如果我可以点击它们时它们会重定向到一个网址。我已经用Toast完成了它但它并没有满足我的需求。我已经搜索过并发现NooYawk弹出。如果有人可以提供我的代码,我将感激不尽。 我是业余爱好者
public class TGpsActivity extends MapActivity {
MapView mapView=null;
MapController mapController=null;
MyLocationOverlay whereAmI=null;
@Override
protected boolean isLocationDisplayed(){
return whereAmI.isMyLocationEnabled();
}
@Override
protected boolean isRouteDisplayed(){
return true;
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
Drawable marker=getResources().getDrawable(R.drawable.pushpin);
marker.setBounds((int) (-marker.getIntrinsicWidth()/2),-marker.getIntrinsicHeight(),(int) (marker.getIntrinsicWidth()/2),0);
mapController=mapView.getController();
mapController.setZoom(15);
InterestingLocations funPlaces= new InterestingLocations(marker);
mapView.getOverlays().add(funPlaces);
GeoPoint pt=funPlaces.getCenterPt();
int latSpan=funPlaces.getLatSpanE6();
int lonSpan=funPlaces.getLonSpanE6();
Log.v("Overlays", "Lat span is " + latSpan);
Log.v("Overlays", "Lon span is " + lonSpan);
MapController mc = mapView.getController();
mc.setCenter(pt);
mc.zoomToSpan((int) (latSpan*1.5), (int)(lonSpan*1.5));
whereAmI= new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(whereAmI);
mapView.postInvalidate();
}
public class InterestingLocations extends ItemizedOverlay{
private ArrayList<OverlayItem> locations = new ArrayList<OverlayItem>();
private GeoPoint center=null;
public InterestingLocations(Drawable marker){
super(marker);
GeoPoint headOffice = new GeoPoint((int)(37.97897823618044*1000000) ,(int)(23.6723855137825*1000000));
GeoPoint computerRoom= new GeoPoint((int)(37.98013047446126*1000000) ,(int)(13.6715030670166*1000000));
locations.add(new OverlayItem(headOffice,"headOffice","headOffice"));
locations.add(new OverlayItem(computerRoom,"computerRoom","computerRoom"));
populate();
}
public GeoPoint getCenterPt(){
if(center==null){
int northEdge= -90000000;
int southEdge= 90000000;
int eastEdge= -180000000;
int westEdge= 180000000;
Iterator<OverlayItem> iter=locations.iterator();
while(iter.hasNext()){
GeoPoint pt=iter.next().getPoint();
if(pt.getLatitudeE6() > northEdge)
northEdge=pt.getLatitudeE6();
if(pt.getLatitudeE6() < southEdge)
southEdge=pt.getLatitudeE6();
if(pt.getLongitudeE6() > eastEdge)
eastEdge=pt.getLongitudeE6();
if(pt.getLongitudeE6() < westEdge)
westEdge=pt.getLongitudeE6();
}
center=new GeoPoint((int)((northEdge+southEdge)/2),(int)((westEdge+eastEdge)/2));
}
return center;
}
@Override
public void draw(Canvas canvas, MapView mapView,boolean shadow)
{
super.draw(canvas, mapView, shadow);
}
@Override
protected OverlayItem createItem(int i){
return locations.get(i);
}
@Override
public int size() {
return locations.size();
}
@Override
protected boolean onTap(int i) {
Toast.makeText(TGpsActivity.this,
locations.get(i).getSnippet(),
Toast.LENGTH_LONG).show();
return(true);
}
}
@Override
public void onResume(){
super.onResume();
whereAmI.enableMyLocation();
whereAmI.runOnFirstFix(new Runnable(){
public void run(){
mapController.setCenter(whereAmI.getMyLocation());
}
});
}
@Override
public void onPause(){
super.onPause();
whereAmI.disableMyLocation();
}
public void myClickHandler(View target){
switch(target.getId()){
case R.id.sat:
mapView.setSatellite(true);
break;
case R.id.traffic:
mapView.setTraffic(true);
break;
case R.id.normal:
mapView.setSatellite(false);
mapView.setTraffic(false);
break;
}
}
}
[更新]
弹出菜单的代码是这个,但我不想显示l
@Override
protected boolean onTap(int i) {
OverlayItem item=getItem(i);
GeoPoint geo=item.getPoint();
Point pt=map.getProjection().toPixels(geo, null);
View view=panel.getView();
((TextView)view.findViewById(R.id.latitude))
.setText(String.valueOf(geo.getLatitudeE6()/1000000.0));
((TextView)view.findViewById(R.id.longitude))
.setText(String.valueOf(geo.getLongitudeE6()/1000000.0));
((TextView)view.findViewById(R.id.x))
.setText(String.valueOf(pt.x));
((TextView)view.findViewById(R.id.y))
.setText(String.valueOf(pt.y));
panel.show(pt.y*2>map.getHeight());
return(true);
}
@Override
public int size() {
return(items.size());}}
class PopupPanel {
View popup;
boolean isVisible=false;
PopupPanel(int layout) {
ViewGroup parent=(ViewGroup)map.getParent();
popup=getLayoutInflater().inflate(layout, parent, false);
popup.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
hide();
}
});
}
View getView() {
return(popup);
}
void show(boolean alignTop) {
RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
if (alignTop) {
lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
lp.setMargins(0, 20, 0, 0);
}
else {
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lp.setMargins(0, 0, 0, 60);
}
hide();
((ViewGroup)map.getParent()).addView(popup, lp);
isVisible=true;
}
void hide() {
if (isVisible) {
isVisible=false;
((ViewGroup)popup.getParent()).removeView(popup);
}
}