简体   繁体   English

Android中Google地图中的位置查询

[英]Location query in Google maps in android

I have made an app utilizing Google Maps. 我已经利用Google Maps开发了一个应用程序。 I have added a marker of my current location in it. 我在其中添加了当前位置的标记。 However, as soon as I open the app, I want it to zoom in to my location instead of showing the whole world at the 95302 23535919711008489 location first. 但是,一旦我打开该应用程序,我希望它可以放大到我的位置,而不是首先在95302 23535919711008489位置上显示整个世界。 How do I accomplish this? 我该如何完成?

Use animateCamera() as below 如下使用animateCamera()

@Override
public void onLocationChanged(Location location) {
    LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 10);
    map.animateCamera(cameraUpdate);
    locationManager.removeUpdates(this);
}

Please read the docs 请阅读文档

  LatLng cameraLatLng = new LatLng(savedLat, savedLng); googleMap = ((SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map)).getMap(); googleMap.animateCamera(CameraUpdateFactory .newLatLngZoom(cameraLatLng, 7)) 

savedLat, savedLng your current location longitude and latitude.You can change zoom number ( 7 ) to your fitting. savedLat,savedLng当前位置的经度和纬度。您可以将缩放数字(7)更改为适合的位置。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM