开发者

getting place name from edit text and placing on the map [duplicate]

This question already has answers here: 开发者_JS百科 Closed 11 years ago.

Possible Duplicate:

i am getting null pointer exception from String placeName = placeText.getText().toString();

here is my code for taking the place name from alert dialog box and i want to mark the place name on the map. can u please help me how can i go futher.by taking the input from these a mark the location om map. . AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle("Enter the places"); dialog.setView(layout);

            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  ;

      }


If you want to add the any views on top off the map,you need to user the MapOverlay class defined in the google provided jar file.

Follow this link.This may solve your problem with simple modifications

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜