我确实使用Google Maps API v2在地图上获取我的位置。是否可以在标记信息中写出正确的地址?
我在互联网上找不到任何有用的东西..
这是我的代码。提前谢谢!
@SuppressLint("NewApi")
public class MainActivity extends Activity implements LocationListener {
GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
}
@Override
public void onLocationChanged(Location location) {
map.clear();
MarkerOptions mp = new MarkerOptions();
mp.position(new LatLng(location.getLatitude(), location.getLongitude()));
mp.title("my position");
map.addMarker(mp);
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(location.getLatitude(), location.getLongitude()), 16));
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
答案 0 :(得分:0)
您想在标记上添加额外信息吗?如果我理解正确,那么你可以添加一个剪刀。
LatLng mark = new LatLng(Double.parseDouble(lat), Double.parseDouble(longi));
map.addMarker(new MarkerOptions().title("MY Position").snippet("Extra info").position(mark));