本文介绍了如何OpenStreetMap的增加气球?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何添加气球像谷歌地图(如这里显示一个)为OpenStreetMap的?这是我的OpenStreetMap $ C $低于C:

 进口org.osmdroid.DefaultResourceProxyImpl;
进口org.osmdroid.ResourceProxy;
进口org.osmdroid.util.GeoPoint;
进口org.osmdroid.views.MapView;
进口org.osmdroid.views.MapController;
进口org.osmdroid.views.MapView;
进口android.os.Bundle;
进口android.app.Activity;
进口android.graphics.drawable.Drawable;

公共类MainActivity延伸活动{

MyItemizedOverlay myItemizedOverlay = NULL;
  私人MapController myMapController;

 @覆盖
 公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
    图形页面图形页面=(图形页面)findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(真正的);
    myMapController = mapView.getController();
    myMapController.setZoom(16);


    绘制对象标记= getResources()getDrawable(android.R.drawable.star_big_on)。
    INT markerWidth = marker.getIntrinsicWidth();
    INT markerHeight = marker.getIntrinsicHeight();
    marker.setBounds(0,markerHeight,markerWidth,0);

    ResourceProxy resourceProxy =新
   DefaultResourceProxyImpl(getApplicationContext());

    myItemizedOverlay =新MyItemizedOverlay(标记,resourceProxy);
    。调用MapView.getOverlays()加(myItemizedOverlay);

    的GeoPoint myPoint1 =新的GeoPoint(24.893379000000000000,67.028060900000010000);
    myItemizedOverlay.addItem(myPoint1myPoint1,myPoint1);
    的GeoPoint myPoint2 =新的GeoPoint(24.824796300000000000,67.031565699999990000);
    myItemizedOverlay.addItem(myPoint2myPoint2,myPoint2);


  }

}


进口的java.util.ArrayList;

进口org.osmdroid.ResourceProxy;
进口org.osmdroid.api.IMapView;
进口org.osmdroid.util.GeoPoint;
进口org.osmdroid.views.overlay.ItemizedOverlay;
进口org.osmdroid.views.overlay.OverlayItem;

进口android.graphics.Point;
进口android.graphics.drawable.Drawable;

公共类MyItemizedOverlay扩展ItemizedOverlay< OverlayItem> {

    私人的ArrayList< OverlayItem> overlayItemList =新的ArrayList< OverlayItem>();

    公共MyItemizedOverlay(可绘制pDefaultMarker,
       ResourceProxy presourceProxy){
     超(pDefaultMarker,presourceProxy);
       // TODO自动生成构造函数存根
     }

     公共无效的addItem(GeoPoint对象磷,标题字符串,字符串片段){
        OverlayItem的newitem =新OverlayItem(标题,片段,P);
        overlayItemList.add(的newitem);
        填充();
     }

     @覆盖
     公共布尔onSnapToItem(INT为arg0,诠释ARG1,ARG2点,IMapView ARG3){
       // TODO自动生成方法存根
       返回false;
     }

     @覆盖
     保护OverlayItem createItem中(INT为arg0){
       // TODO自动生成方法存根
       返回overlayItemList.get(为arg0);
     }

     @覆盖
     公众诠释大小(){
       // TODO自动生成方法存根
       返回overlayItemList.size();
     }

}
 

我是同一个问题,现在我找到了一个方法:

  1. 下载 osmbonuspack 在这里:的https:/ /$c$c.google.com/p/osmbonuspack/

  2. 按照此code:

     的ArrayList< ExtendedOverlayItem> overlayItemArray =新的ArrayList< ExtendedOverlayItem>();
    
    ExtendedOverlayItem项目=新ExtendedOverlayItem(标题,描述,新的GeoPoint(双纬度,经度双),这一点);
    
    //创建一个层气球
    
    ItemizedOverlayWithBubble< ExtendedOverlayItem> poiMarkers =新ItemizedOverlayWithBubble< ExtendedOverlayItem>(这一点,overlayItemArray,图形页面,新的CustomMapInfoWindow(图形页面));
    
    //添加图层
    。调用MapView.getOverlays()加(poiMarkers);
     

  3. 创建了一个名为 CustomMapInfoWindow

     进口org.osmdroid.bonuspack.overlays.DefaultInfoWindow;
    进口org.osmdroid.bonuspack.overlays.ExtendedOverlayItem;
    进口org.osmdroid.views.MapView;
    
    公共类CustomMapInfoWindow扩展DefaultInfoWindow {
    
        公共CustomMapInfoWindow(图形页面图形页面){
            超(R.layout.bonuspack_bubble,图形页面);
    
        }
    
        @覆盖
        公共无效的OnOpen(ExtendedOverlayItem项目){
            super.onOpen(项目);
        }
    }
     

  4. 到<一个href="https://$c$c.google.com/p/osmbonuspack/source/browse/#svn%2Ftrunk%2FOSMBonusPackDemo%2Fres%2Flayout"相对=nofollow> OSMBONUSPACKDEMO REPOSITORY 并获得 bonuspack_bubble.xml 可绘制绘制-MDPI 的文件夹。

How do I add balloons like those on Google Maps (such as the one shown here) into OpenStreetMap? This is my OpenStreetMap code below:

import org.osmdroid.DefaultResourceProxyImpl;
import org.osmdroid.ResourceProxy;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.Drawable;

public class MainActivity extends Activity {

MyItemizedOverlay myItemizedOverlay = null;
  private MapController myMapController;

 @Override
 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);
    myMapController = mapView.getController();
    myMapController.setZoom(16);


    Drawable marker=getResources().getDrawable(android.R.drawable.star_big_on);
    int markerWidth = marker.getIntrinsicWidth();
    int markerHeight = marker.getIntrinsicHeight();
    marker.setBounds(0, markerHeight, markerWidth, 0);

    ResourceProxy resourceProxy = new   
   DefaultResourceProxyImpl(getApplicationContext());

    myItemizedOverlay = new MyItemizedOverlay(marker, resourceProxy);
    mapView.getOverlays().add(myItemizedOverlay);

    GeoPoint myPoint1 = new GeoPoint(24.893379000000000000, 67.028060900000010000);
    myItemizedOverlay.addItem(myPoint1, "myPoint1", "myPoint1");
    GeoPoint myPoint2 = new GeoPoint(24.824796300000000000, 67.031565699999990000);
    myItemizedOverlay.addItem(myPoint2, "myPoint2", "myPoint2");


  } 

}


import java.util.ArrayList;

import org.osmdroid.ResourceProxy;
import org.osmdroid.api.IMapView;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.overlay.ItemizedOverlay;
import org.osmdroid.views.overlay.OverlayItem;

import android.graphics.Point;
import android.graphics.drawable.Drawable;

public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {

    private ArrayList<OverlayItem> overlayItemList = new ArrayList<OverlayItem>();

    public MyItemizedOverlay(Drawable pDefaultMarker,
       ResourceProxy pResourceProxy) {
     super(pDefaultMarker, pResourceProxy);
       // TODO Auto-generated constructor stub
     }

     public void addItem(GeoPoint p, String title, String snippet){
        OverlayItem newItem = new OverlayItem(title, snippet, p);
        overlayItemList.add(newItem);
        populate(); 
     }

     @Override
     public boolean onSnapToItem(int arg0, int arg1, Point arg2, IMapView arg3) {
       // TODO Auto-generated method stub
       return false;
     }

     @Override
     protected OverlayItem createItem(int arg0) {
       // TODO Auto-generated method stub
       return overlayItemList.get(arg0);
     }

     @Override
     public int size() {
       // TODO Auto-generated method stub
       return overlayItemList.size();
     }

}
解决方案

I was with the same question and now I found a way:

  1. Download the osmbonuspack here: https://code.google.com/p/osmbonuspack/

  2. Follow this code:

    ArrayList<ExtendedOverlayItem> overlayItemArray = new ArrayList<ExtendedOverlayItem>();
    
    ExtendedOverlayItem item = new ExtendedOverlayItem("Title, "Description, new GeoPoint(Double latitude, Double longitude), this);
    
    //creates a layer with ballons
    
    ItemizedOverlayWithBubble<ExtendedOverlayItem> poiMarkers = new ItemizedOverlayWithBubble<ExtendedOverlayItem>(this, overlayItemArray, mapView, new CustomMapInfoWindow(mapView));
    
    // add the layer
    mapView.getOverlays().add(poiMarkers);
    

  3. Create a class called CustomMapInfoWindow:

    import org.osmdroid.bonuspack.overlays.DefaultInfoWindow;
    import org.osmdroid.bonuspack.overlays.ExtendedOverlayItem;
    import org.osmdroid.views.MapView;
    
    public class CustomMapInfoWindow extends DefaultInfoWindow {
    
        public CustomMapInfoWindow(MapView mapView) {
            super(R.layout.bonuspack_bubble, mapView);
    
        }
    
        @Override
        public void onOpen(ExtendedOverlayItem item) {
            super.onOpen(item);
        }
    }
    

  4. Go to OSMBONUSPACKDEMO REPOSITORY and get bonuspack_bubble.xml and the drawables into drawable-mdpi folder.

这篇关于如何OpenStreetMap的增加气球?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 00:01