2011-12-11 99 views
1

谷歌地图,它允许我们指向任何我们想要的位置。引脚指向后,推针顶部会出现“Bubble”弹出框。我可以知道如何做弹出窗口框吗?任何代码显示?现在我正在使用警告对话框,但我希望它是“泡泡”弹出窗口。泡泡弹出框

List<Overlay> mapOverlays = mapView.getOverlays(); 
     MapOverlay mapOverlay = new MapOverlay(); 

     mapOverlays.add(mapOverlay); 

     // obtain gps location 
     lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 

     locationListener = new MyLocationListener(); 

     lm.requestLocationUpdates(
     // LocationManager.GPS_PROVIDER, 
       LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); 
    } 

    private class MyLocationListener implements LocationListener { 

     @Override 
     public void onLocationChanged(Location loc) { 

      k = new GeoPoint((int) (loc.getLatitude() * 1E6), 
        (int) (loc.getLongitude() * 1E6)); 
      mc.animateTo(k); 
      mc.setZoom(18); 

      // Add a location marker 
      MapOverlay mapOverlay = new MapOverlay(); 
      List<Overlay> listofOverlays = mapView.getOverlays(); 
      listofOverlays.clear(); 
      listofOverlays.add(mapOverlay); 

      // invalidate() method forces the MapView to be redrawn 
      mapView.invalidate(); 
     } 

     @Override 
     public void onProviderDisabled(String provider) { 
     } 

     @Override 
     public void onProviderEnabled(String provider) { 
     } 

     @Override 
     public void onStatusChanged(String provider, int status, Bundle extras) { 
     } 
    } 

    @Override 
    protected boolean isRouteDisplayed() { 
     return false; 
    } 

    class MapOverlay extends com.google.android.maps.Overlay { 

     @Override 
     public boolean onTap(final GeoPoint p, MapView mapView) { 
      // TODO Auto-generated method stub 

      k = p; 
      mc = mapView.getController(); 
      mc.animateTo(p); 

      mapView.invalidate(); 

      Geocoder geoCoder = new Geocoder(getBaseContext(), 
        Locale.getDefault()); 
      try { 
       List<Address> addresses = geoCoder.getFromLocation(
         p.getLatitudeE6()/1E6, p.getLongitudeE6()/1E6, 1); 
       String add = ""; 
       if (addresses.size() > 0) { 
        for (int i = 0; i < addresses.get(0) 
          .getMaxAddressLineIndex(); i++) 
         add += addresses.get(0).getAddressLine(i) + "\n"; 
        txtAddress.setText("Address: " + add); 
       } 
@Override 
     public boolean draw(Canvas canvas, MapView mapView, boolean shadow, 
       long when) { 
      super.draw(canvas, mapView, shadow); 
      if (k != null) { 
       // ---translate the GeoPoint to screen pixels--- 
       Point screenPts = new Point(); 
       mapView.getProjection().toPixels(k, screenPts); 

       // ---add the marker--- 
       Bitmap bmp = BitmapFactory.decodeResource(getResources(), 
         R.drawable.passenger); 
       canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 50, null); 
      } 
      return true; 
     } 
    } 
} 

回答

0

听起来像是你正在寻找的InfoWindow。顺便说一句,在新版本的API中,它们没有圆角(它们看起来更像盒子,不像气泡)。您可以通过在加载地图API的JavaScript网址中请求以前版本的API来恢复旧版本。

+0

我真的不明白你的意思。你有任何代码示例?我想如何把代码放入? – sowhat

+0

您是否阅读过我发给您的链接?它有代码示例。您也可以在这里查看InfoWindow API的参考资料:http://code.google.com/apis/maps/documentation/javascript/reference.html#InfoWindow – danludwig

1

我目前正在制作一个地图应用程序,我还需要显示'Bubble'弹出窗口,以下博客文章对我有相当帮助。

This first post显示了如何使用视图中嵌入的9补丁图像来生成弹出窗口。代码没问题,但确实留下了一些未回答的问题,一些评论者已经要求澄清一些额外的源代码。

This post from the Android Developers blog解释什么是9修补图像是如何创建一个。

使用这两个帖子,我能够将一些代码放在一起,这很好,所以希望您能够操作它以满足您的需求。

+1

只需对此进行更新 - 第一篇文章位于我自己的博客上,现在我已经在那里添加了一个链接到完整的源代码,以防万一在任何时候帮助任何人。 – actionshrimp

+0

感谢您的更新 - 和来源,我发现这篇文章真的很有帮助。 – DilbertDave

0

谷歌不提供API来做到这一点,看看this。 Victor的答案给出了一个链接到适合该法案的开源代码。