簡體   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