如何在Android中的自定义地图标记中添加字符串?

时间:2012-04-06 15:15:32

标签: android google-maps

我已经通过查找用户位置创建了一个位于我的地图上的地图标记,但我正在尝试将字符串添加到地图标记中,并且无法使其工作。这是我的onCreate方法,其中设置了位置。该方法的最后一部分显示将精确定位在位置,我认为重叠项将采用如下字符串参数:

      @Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map);

        // Displaying Zooming controls
        mapView= (MapView) findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(true);

        //Manually place a pin by touching the map
        touchy t = new touchy();
        overlayList = mapView.getOverlays();
        overlayList.add(t);
        compass = new MyLocationOverlay(Maps.this, mapView);
        overlayList.add(compass);
        controller = mapView.getController();


        d = getResources().getDrawable(R.drawable.androidmarker);


      //placing pinpoint at location
        lm =(LocationManager) getSystemService(Context.LOCATION_SERVICE);
        Criteria crit = new Criteria();

        towers = lm.getBestProvider(crit, false);

        Location location = lm.getLastKnownLocation(towers);

        if(location != null){

            lat = (int) (location.getLatitude()* 1E6);
            longi = (int) (location.getLongitude()* 1E6);

              GeoPoint ourLocation = new GeoPoint(lat, longi);
              controller.animateTo(ourLocation);
            controller.setZoom(6);
            OverlayItem overlayitem = new OverlayItem(ourLocation, "First string", "Second string");
            HelloItemizedOverlay custom = new HelloItemizedOverlay(d, Maps.this);
            custom.insertPinpoint(overlayitem);
            overlayList.add(custom);
        }
        else{
            Toast.makeText(Maps.this, "Couldn't get provider", Toast.LENGTH_SHORT).show();
        }

    }

谁能看到我做错了什么?这是错误的方法吗?最后,我想将一个名称和高分传递给将从另一个类中检索为两个字符串的位置。

我很感激任何建议。

1 个答案:

答案 0 :(得分:2)

遵循以下教程: http://codemagician.wordpress.com/2010/05/06/android-google-mapview-tutorial-done-right/

在此他正在创建一个ItemizedOverly

HelloItemizedOverlay extends ItemizedOverlay<OverlayItem>

这将有助于您添加带文字的地图叠加层