2011-11-25 174 views
0

映射我试图以应用教程:http://deckjockey.blogspot.com/2010/01/android-baloon-display-on-map.html?showComment=1322215574598#c3178096297154271518我的代码,我现在面临一个小的困难 - 没有关系的工作,气球信息的Android

这里是我的代码:

public void HuntCl(View v) throws UnknownHostException, IOException{ 
        String sentenceX, sentenceY = null;   

    try { 

    clientSocket = new Socket("10.0.2.2", 1234); 
    Log.d("LatitudeE6", ""+point.getLatitudeE6()); 
    Log.d("LongitudeE6", ""+point.getLongitudeE6()); 
    DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());   
    BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); 
    sentenceX = ""+point.getLatitudeE6(); 
    sentenceY = ""+point.getLongitudeE6(); 
    outToServer.writeBytes(sentenceX + " "+ sentenceY+'\n'); 

    String ciekawostka = inFromServer.readLine(); 
    String [] holder = ciekawostka.split("\\s+"); 

    for(int i =0; i<holder.length; i++){ 

    x = Integer.valueOf(holder[i]); 
    y= Integer.valueOf(holder[i+1]); 
    marker=getResources().getDrawable(R.drawable.pin); 
    marker.setBounds(0, 0, marker.getIntrinsicWidth(), 
    marker.getIntrinsicHeight()); 
    POI funPlaces = new POI(marker,x,y); 
    mapView.getOverlays().add(funPlaces); 
    GeoPoint pt = funPlaces.getCenter(); 
    mapView.getController().setCenter(pt); 
    } 


    } catch (Exception e) { 
     Log.d("error","TCP Error: " + e.toString()); 
    } 

      } 


class POI extends ItemizedOverlay { 
     private List<OverlayItem> locations = new ArrayList<OverlayItem>(); 

     private Drawable marker; 
    public POI(Drawable marker, int tX, int tY) 
    { 
    super(marker); 
    this.marker=marker; 

    LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    BaloonLayout noteBaloon = (BaloonLayout) layoutInflater.inflate(R.layout.ballon, null); 


    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(200,100); 
    layoutParams.addRule(RelativeLayout.CENTER_VERTICAL); 
    layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL); 
    noteBaloon.setLayoutParams(layoutParams); 

    mapView.removeView(noteBaloon); 
    noteBaloon.setVisibility(View.VISIBLE); 
    // TextView textmsg = (TextView) noteBaloon.findViewById(R.id.note_text); 
    TextView textmsg = (TextView) noteBaloon.findViewById(R.id.text); 
    textmsg.setText("I am a Popup Balloon!!!"); 

    mapView.addView(noteBaloon, new MapView.LayoutParams(200,200, new OverlayItem(new GeoPoint((int)(tX),(int)(tY)), "Seven Lagoon", "Seven Lagoon").getPoint(),MapView.LayoutParams.BOTTOM_CENTER)); 
    mapView.setEnabled(false); 


    locations.add(new OverlayItem(new GeoPoint((int)(tX),(int)(tY)), "Seven Lagoon", "Seven Lagoon")); 

    populate(); 
    } 
    @Override 
    public void draw(Canvas canvas, MapView mapView, boolean shadow) { 

    super.draw(canvas, mapView, shadow); 

    boundCenterBottom(marker); 
    } 
     @Override 
     protected OverlayItem createItem(int i) { 
     return locations.get(i); 
     } 
      @Override 
      public int size() { 
      return locations.size(); 
      } 

      } 

} 
+0

它不工作方式?你有任何错误或没有显示? – user370305

+0

该死的,对不起:)。那么它不会放置标记,并且没有气球,​​但地图工作正常 – iie

回答

2

android-mapviewballoons当使用谷歌地图时,库提供了一种使用简单的信息气球来注释地图叠加项目的简单方法。在你的基地

做同样的方式创建

BalloonItemizedOverlay

的一个子类ItemizedOverlay

类。

下面是一个示例输出

enter image description here