android - 无法单独获取选定的叠加值

标签 android google-maps android-alertdialog alerts

我正在使用一个面向谷歌地图的 android 项目,现在我在这个类中遇到了问题我类我使用某些覆盖来标记最近的地方当我们触摸特定的覆盖时它会显示一个包含名称和引用的警告框现在我我现在使用 getsnipet() 方法检索引用我不想显示警报对话框但是当我禁用那个东西时我无法获得引用任何人都可以帮助我修复这个错误这是我的代码......

public class PlacesMapActivity extends MapActivity {
    // Nearest places
    PlacesList nearPlaces;

    // Map view
    MapView mapView;

    // Map overlay items
    List<Overlay> mapOverlays;

    AddItemizedOverlay itemizedOverlay;

    GeoPoint geoPoint;
    // Map controllers
    MapController mc;

    double latitude;
    double longitude;
    OverlayItem overlayitem;

    String p_u_name;
    Place reference;


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

        // Getting intent data
        Intent i = getIntent();

        p_u_name=i.getStringExtra("p_u_name");
        reference = (Place) i.getSerializableExtra("place_reference");


        i.putExtra("p_u_name",p_u_name);



        // Users current geo location
        String user_latitude = i.getStringExtra("user_latitude");
        String user_longitude = i.getStringExtra("user_longitude");

        System.out.println("sarath"+user_latitude + user_longitude);

        // Nearplaces list
        nearPlaces = (PlacesList) i.getSerializableExtra("near_places");

        mapView = (MapView) findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(true);

        mapOverlays = mapView.getOverlays();

        // Geopoint to place on map
        geoPoint = new GeoPoint((int) (Double.parseDouble(user_latitude) * 1E6),
                (int) (Double.parseDouble(user_longitude) * 1E6));

        // Drawable marker icon
        Drawable drawable_user = this.getResources()
                .getDrawable(R.drawable.mark_red);

        itemizedOverlay = new AddItemizedOverlay(drawable_user, this);

        // Map overlay item
        overlayitem = new OverlayItem(geoPoint, "Your Location",
                "That is you!");

        itemizedOverlay.addOverlay(overlayitem);

        mapOverlays.add(itemizedOverlay);
        itemizedOverlay.populateNow();

        // Drawable marker icon
        Drawable drawable = this.getResources()
                .getDrawable(R.drawable.mark_blue);

        itemizedOverlay = new AddItemizedOverlay(drawable, this);

        mc = mapView.getController();

        // These values are used to get map boundary area
        // The area where you can see all the markers on screen
        int minLat = Integer.MAX_VALUE;
        int minLong = Integer.MAX_VALUE;
        int maxLat = Integer.MIN_VALUE;
        int maxLong = Integer.MIN_VALUE;

        // check for null in case it is null
        if (nearPlaces.results != null) {
            // loop through all the places
            for (Place place : nearPlaces.results) {
                latitude = place.geometry.location.lat; // latitude
                longitude = place.geometry.location.lng; // longitude

                // Geopoint to place on map
                geoPoint = new GeoPoint((int) (latitude * 1E6),
                        (int) (longitude * 1E6));
                String s = place.formatted_address;
                String p = place.formatted_phone_number;
                String n = s;
                System.out.println("sarath"+s);



                // Map overlay item
                                 //Here it passes the selected overlay name and reference to the alerdialog box 
                overlayitem = new OverlayItem(geoPoint,place.name,place.reference);

                i.putExtra("place_reference", place.reference);

//              System.out.println("this is mapactivity and reference is:"+ab);

                itemizedOverlay.addOverlay(overlayitem);



                // calculating map boundary area
                minLat  = (int) Math.min( geoPoint.getLatitudeE6(), minLat );
                minLong = (int) Math.min( geoPoint.getLongitudeE6(), minLong);
                maxLat  = (int) Math.max( geoPoint.getLatitudeE6(), maxLat );
                maxLong = (int) Math.max( geoPoint.getLongitudeE6(), maxLong );
            }
            mapOverlays.add(itemizedOverlay);

            // showing all overlay items
            itemizedOverlay.populateNow();
        }

        // Adjusting the zoom level so that you can see all the markers on map
        mapView.getController().zoomToSpan(Math.abs( minLat - maxLat ), Math.abs( minLong - maxLong ));

        // Showing the center of the map
        mc.animateTo(new GeoPoint((maxLat + minLat)/2, (maxLong + minLong)/2 ));
        mapView.postInvalidate();

    }

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

}

最佳答案

您的问题很不清楚……我认为“引用”是指“描述”,在这种情况下,您使用 getsnippet() 是正确的。如果您已经通过 AlertDialog 看到了 String,那么取出对话框应该不会妨碍您看到代码 fragment 。您能否就您的确切问题向我们提供更多信息?

关于android - 无法单独获取选定的叠加值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12968670/

相关文章:

c# - Unity3D - Android 通信?

Angular、Google map 、如何从 map 获取标记列表并在其上使用 onClick 事件?

javascript - 如何在谷歌地图上显示项目类似于谷歌显示其结果的方式

javascript - 谷歌地图设置中心。专注于新位置

Java,从多个类调用AlertDialog

Android 从 map 流平均

android - 如何在非 Activity 类 (LocationManager) 中使用 getSystemService?

android - ActionBar 列表导航重叠 fragment

Android 闹钟无法使用 AlarmManager

android - 如何更改 AlertDialog.Builder AppCompat 中项目的颜色?