0

我通过查找用户位置创建了一个地图标记,该标记位于我的地图上,但我正在尝试向地图标记添加字符串,但无法使其正常工作。这是我设置位置的 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();
        }

    }

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

我很感激任何建议。

4

1 回答 1

2

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

在这个他正在创建一个 ItemizedOverly

HelloItemizedOverlay extends ItemizedOverlay<OverlayItem>

这将帮助您添加带有文本的地图叠加层

于 2012-04-06T15:42:07.113 回答