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

发布于 2024-11-16 05:19:33 字数 3163 浏览 0 评论 0原文

可能的重复:
我从字符串中获取空指针异常placeName = placeText.getText().toString();

这是我从警报对话框中获取地名的代码,我想在地图上标记地名。你能帮我进一步了解一下吗?通过从这些数据中获取输入,在地图上标记位置。 。 AlertDialog.Builder 对话框 = new AlertDialog.Builder(this); dialog.setTitle("请输入地点"); 对话框.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  ;

      }

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  ;

      }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哭泣的笑容 2024-11-23 05:19:33

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

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文