【发布时间】:2017-07-27 07:54:56
【问题描述】:
我正在研究谷歌地图 api v2。我有一个按钮,可以将标记添加到我的当前位置。
地图可以正确定位我的位置,但有时(不是每次)当我想在该位置添加标记时,标记会远离蓝点。
我想将我的标记准确地添加到蓝点上。
这是我的 findMe 按钮代码:
ImageButton findMyLocation_btn = (ImageButton) findViewById(R.id.findme);
if (findMyLocation_btn != null) {
findMyLocation_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
buildAlertMessageNoGps();
} else {
currentLocation = mMap.getMyLocation();
if ( marker1 == null && currentLocation != null) {
new onMyLocationClick().execute();
}
}
}
});
和 onMyLocationClick()
private class onMyLocationClick extends AsyncTask{
@Override
protected Object doInBackground(Object[] params) {
Geocoder gc = new Geocoder(MainActivity.this);
List<Address> list = null;
try {
list = gc.getFromLocation(currentLocation.getLatitude(), currentLocation.getLongitude(), 1);
} catch (Exception ex) {
ex.printStackTrace();
}
if (list != null) {
add = list.get(0);
}
try {
origin = new LatLng(add.getLatitude(),add.getLongitude());
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute (Object o){
createMarker(add.getLatitude(), add.getLongitude(), add.getLocality(), add.getSubLocality());
}
}
【问题讨论】:
标签: android dictionary