繁体   English   中英

如何通过使用Google Maps获取用户当前位置并在android中放置标记

[英]How can i get the user current location and put marker on it in android by using google maps

我开发了具有Google API的应用程序,因此我可以在我的应用程序中放置地图。我在获取用户当前位置时遇到问题,我要:当用户打开地图活动时,它会在她的location.i上显示地图和标记。但是我在用户当前位置和标记上遇到了问题。 这是我的代码(向我展示了海洋!!):alert.setButton2(“获取地址”,新的DialogInterface.OnClickListener(){

                        public void onClick(DialogInterface dialog,
                                int which) {
                            // TODO Auto-generated method stub
                            Geocoder geocoder = new Geocoder(
                                    getBaseContext(), Locale.getDefault());

                            try {
                                List<Address> address = geocoder.getFromLocation(touchedPoint.getLatitudeE6() / 1E6,touchedPoint.getLatitudeE6() / 1E6,1);
                                OverlayItem overlayItem = new OverlayItem( touchedPoint, "Whats up", "2nd String");
                                CustomPinpoint custom = new CustomPinpoint(d,MapsActivity.this);
                                custom.insertPinpoint(overlayItem);
                                overlaylist.add(custom);
                                if (address.size() > 0) {
                                    String display = "";
                                    for (int i = 0; i < address.get(0)
                                            .getMaxAddressLineIndex(); i++) {
                                        display += address.get(0)
                                                .getAddressLine(i) + "\n";
                                    }

                                    Toast t = Toast.makeText(
                                            getBaseContext(), display,
                                            Toast.LENGTH_LONG);
                                    t.show();

                                }
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } finally {
                            }
                        }
                    });

我对地图有噩梦,请修正我的代码

请检查以下示例

1) http://eagle.phys.utk.edu/guidry/android/mapOverlayDemo.html

2) http://androidmyway.wordpress.com/2012/02/26/map-marker-dragging

在第二个中,您可以检查如何获取地址。

谢谢

如果您只想向用户显示当前位置,则可以在mapactivity中使用MyLocationOverlay类。 它将在位置本身上绘制标记。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM