简体   繁体   English

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

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

i develop the application that has Google API so i can put map in my app i have problem in get user Current location, i want : when the user open map Activity it display the map and marker on her location.i already doing google API stuff but i faced problem with USER CURRENT LOCATION AND MARKER ON IT. 我开发了具有Google API的应用程序,因此我可以在我的应用程序中放置地图。我在获取用户当前位置时遇到问题,我要:当用户打开地图活动时,它会在她的location.i上显示地图和标记。但是我在用户当前位置和标记上遇到了问题。 this is my code(it is shows me in ocean !!): alert.setButton2("get an address", new DialogInterface.OnClickListener() { 这是我的代码(向我展示了海洋!!):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 {
                            }
                        }
                    });

i Have a nightmare about Map, PLEASE FIX MY CODE 我对地图有噩梦,请修正我的代码

please check below example 请检查以下示例

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

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

in second one you can check how to get address. 在第二个中,您可以检查如何获取地址。

Thank You 谢谢

if you just want to show users current location you could use MyLocationOverlay class in mapactivity. 如果您只想向用户显示当前位置,则可以在mapactivity中使用MyLocationOverlay类。 it will draw the marker on the location itself. 它将在位置本身上绘制标记。

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

相关问题 如何在不使用谷歌地图和其他地图的情况下获取用户当前位置? - How can I get user current location without using google maps and other maps? 如何获得正常的谷歌地图蓝色当前位置标记? - How can I get the normal Google Maps blue current location marker? 获取用户当前位置并在Google地图中确定位置 - Get user current location and determine it in Google maps 如何在Android Google Maps API V2中获取当前位置? - How to get current location in android google maps api V2? 如何从Google Maps android中的当前位置不断检测附近的标记位置? - How to constantly detect nearby marker locations from current location in Google Maps android? Android Google Maps API v2中的用户位置标记 - Marker on user location in Android Google Maps API v2 我怎样才能让它在谷歌地图上显示一个标记? - how can I get this to display a marker on google maps? 如何从 Google 地图中的可拖动标记中获取 position? - How can I get position from a draggable marker in Google Maps? 如何在Android Studio中以字符串形式获取地图标记的位置? - How can I get the location, as a string, of a map marker in Android studio? 在 Google Maps v2 上计算当前位置和标记之间的距离 - Calculate Distance between Current Location and Marker on Google Maps v2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM