【问题标题】:how to display map in android with marker如何使用标记在android中显示地图
【发布时间】:2011-05-26 14:41:56
【问题描述】:

我正在开发 android 应用程序,我在这方面完全是新手。所以我想知道如何在地图中显示标记,以及如何在特定时间改变他的位置,比如定义线程或背景中的任何东西,这将发送纬度和经度值并且标记在上面移动

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    如果您只想显示一个项目,MapView.addView() 和稍后使用 setLayoutParams 更新位置就可以了。

    private ImageView mCurrentPointer;
    
    @Override
    public void onLocationChanged(Location l) {
        int latitude = (int) (l.getLatitude() * 1e6);
        int longitude = (int) (l.getLongitude() * 1e6);
        // Prepare new LayoutParams object that centers on our new latitude/longitude
        MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, 
                MapView.LayoutParams.WRAP_CONTENT, new GeoPoint(latitude, longitude),
                MapView.LayoutParams.CENTER);
    
        if (mCurrentPointer == null) {
            // If "current location" pin is null, we haven't added it
            // to MapView yet. So instantiate it and add it to MapView:
            mCurrentPointer = new ImageView(this); 
            mCurrentPointer.setImageResource(R.drawable.ic_maps_indicator_current_position);
            mMapView.addView(mCurrentPointer, lp);
        } else {
            // If it's already added, just update its location
            mCurrentPointer.setLayoutParams(lp);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-14
      • 1970-01-01
      • 1970-01-01
      • 2021-12-18
      相关资源
      最近更新 更多