从编辑文本获取地名并放置在地图上

时间:2011-06-21 09:48:56

标签: java android maps dialog

  

可能重复:
  i am getting null pointer exception from String placeName = placeText.getText().toString();

这是我从警告对话框中取出地名的代码,我想在地图上标记地名。你可以帮助我,我怎么能进一步。从这些标记的位置om地图输入。 。                 AlertDialog.Builder dialog = new AlertDialog.Builder(this);                 dialog.setTitle(“输入地点”);                 dialog.setView(布局);

            final EditText placeText = (EditText)layout.findViewById(R.id.strtplace);   
            final String placeName = placeText.getText().toString();
            dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {



                @Override
                public void onClick(DialogInterface dialog, int id) {
                    // TODO Auto-generated method stub

                   //Break from execution if the user has not entered anything in the field
                        if(placeName.compareTo("")==0) 
                        numberOptions = 5;
                        String [] optionArray = new String[numberOptions];
                        Geocoder gcoder = new Geocoder(TravellogActivity.this);  

                        try{
                            List<Address> results = gcoder.getFromLocationName(placeName,numberOptions);
                            Iterator<Address> locations = results.iterator();
                            String raw = "\nRaw String:\n";
                            String country;
                            int opCount = 0;
                            while(locations.hasNext()){
                                Address location = locations.next();
                                lat = location.getLatitude();
                                lon = location.getLongitude();
                                country = location.getCountryName();
                                if(country == null) {
                                    country = "";
                                } else {
                                    country =  ", "+country;
                                }
                                raw += location+"\n";
                                optionArray[opCount] = location.getAddressLine(0)+", "+location.getAddressLine(1)+country+"\n";
                                opCount ++;
                            }
                            Log.i("Location-List", raw);
                            Log.i("Location-List","\nOptions:\n");
                            for(int i=0; i<opCount; i++){
                                Log.i("Location-List","("+(i+1)+") "+optionArray[i]);
                            }

                        } catch (IOException e){
                            Log.e("Geocoder", "I/O Failure; is network available?",e);
                        }           

                               // p = new GeoPoint((int)(latE6),(int)(lonE6));


                    }                       
                });

            dialog.show();
            break;

            }



        return false  ;

      }

1 个答案:

答案 0 :(得分:0)

如果您想在地图上添加任何视图,您需要使用google提供的jar文件中定义的MapOverlay类。

请点击此链接。这可以通过简单的修改来解决您的问题

http://www.bogotobogo.com/Android/android17MapView.html