【发布时间】:2014-03-12 12:47:04
【问题描述】:
我想使用 Google map Api 在我的当前位置上标记。我在 Android 手机上对其进行了测试,但我只得到了一张地图。我的当前位置没有标记。甚至我在代码中放入的吐司也没有显示。谁能帮我这个。 我在下面发布我的代码:
public class MainActivity extends Activity implements LocationListener {
GoogleMap map;
@Override
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);
Toast.makeText(getApplicationContext(),
location.getLatitude() +", "+location.getLongitude(),
Toast.LENGTH_LONG).show();
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(location.getLatitude(), location.getLongitude()), 16));
} }
【问题讨论】:
-
在 manifest.xml 中添加了所需的权限
-
我已将所有权限添加到清单中。