Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 地图在更新更改时缩小_Android_Google Maps - Fatal编程技术网

Android 地图在更新更改时缩小

Android 地图在更新更改时缩小,android,google-maps,Android,Google Maps,我在Android Studio上使用谷歌地图。我正在尝试制作一个跟踪用户的gps。我的问题是,每次我用手机移动时,每次位置更新时,应用程序都会缩小地图。我不知道为什么会这样。谢谢你们 这是我的密码 private GoogleMap mMap; LocationManager locationManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onC

我在Android Studio上使用谷歌地图。我正在尝试制作一个跟踪用户的gps。我的问题是,每次我用手机移动时,每次位置更新时,应用程序都会缩小地图。我不知道为什么会这样。谢谢你们

这是我的密码

private GoogleMap mMap;
    LocationManager locationManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
        locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

            return;
        }

        if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {

            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, new LocationListener() {
                @Override
                public void onLocationChanged(Location location) {
                    double latitude = location.getLatitude();
                    double longitude = location.getLongitude();

                    LatLng latLng = new LatLng(latitude, longitude);
                    Geocoder geocoder = new Geocoder(getApplicationContext());
                    try {
                        List<Address> addressList = geocoder.getFromLocation(latitude, longitude, 1);
                        String str = addressList.get(0).getLocality()+",";
                        str += addressList.get(0).getCountryName();
                        mMap.addMarker(new MarkerOptions().position(latLng).title(str));
                        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 10.2f));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }


        }
        else if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
                @Override
                public void onLocationChanged(Location location) {
                    double latitude = location.getLatitude();
                    double longitude = location.getLongitude();

                    LatLng latLng = new LatLng(latitude, longitude);
                    Geocoder geocoder = new Geocoder(getApplicationContext());
                    try {
                        List<Address> addressList = geocoder.getFromLocation(latitude, longitude, 1);
                        String str = addressList.get(0).getLocality()+",";
                        str += addressList.get(0).getCountryName();
                        mMap.addMarker(new MarkerOptions().position(latLng).title(str));
                        mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }


    }
私有谷歌地图mMap;
地点经理地点经理;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_映射);
//获取SupportMapFragment,并在地图准备好使用时收到通知。
SupportMapFragment mapFragment=(SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map);
getMapAsync(这个);
locationManager=(locationManager)getSystemService(位置服务);
if(ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS\u FINE\u LOCATION)!=PackageManager.permission\u已授予和&ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS\u LOCATION)!=PackageManager.permission\u已授予){
返回;
}
if(locationManager.isProviderEnabled(locationManager.NETWORK_PROVIDER)){
locationManager.RequestLocationUpdate(locationManager.NETWORK_提供程序,0,0,新LocationListener(){
@凌驾
已更改位置上的公共无效(位置){
双纬度=location.getLatitude();
double longitude=location.getLongitude();
LatLng LatLng=新LatLng(纬度、经度);
Geocoder Geocoder=新的Geocoder(getApplicationContext());
试一试{
List addressList=geocoder.getFromLocation(纬度、经度,1);
字符串str=addressList.get(0.getLocality()+“,”;
str+=addressList.get(0.getCountryName();
mMap.addMarker(新的MarkerOptions().position(latLng).title(str));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,10.2f));
}捕获(IOE异常){
e、 printStackTrace();
}
}
}
else if(locationManager.isProviderEnabled(locationManager.GPS\U提供程序)){
locationManager.RequestLocationUpdate(locationManager.GPS_提供程序,0,0,新LocationListener(){
@凌驾
已更改位置上的公共无效(位置){
双纬度=location.getLatitude();
double longitude=location.getLongitude();
LatLng LatLng=新LatLng(纬度、经度);
Geocoder Geocoder=新的Geocoder(getApplicationContext());
试一试{
List addressList=geocoder.getFromLocation(纬度、经度,1);
字符串str=addressList.get(0.getLocality()+“,”;
str+=addressList.get(0.getCountryName();
mMap.addMarker(新的MarkerOptions().position(latLng).title(str));
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
}捕获(IOE异常){
e、 printStackTrace();
}
}
}

您使用的是
GoogleMap.moveCamera
所以它在移动,在
LocationManager.NETWORK\u PROVIDER
中,您使用的是缩放功能移动相机。如果您不想缩放,您可以使用
CameraUpdateFactory.NewLatling
就像您在
LocationManager.GPS\u PROVIDER
中使用的那样>因此,它正在移动,并且在
LocationManager.NETWORK\u PROVIDER
中,您正在使用Zoom移动相机。如果您不想使用Zoom,可以使用
CameraUpdateFactory.newLatLng
,就像您在
LocationManager.GPS\u PROVIDER
中所做的那样替换行:

mMap.移动摄像头(摄像头更新工厂。新LATLNGZOOM(latLng,10.2f))

与:

mMap.移动摄像头(CameraUpdateFactory.newLatLng(latLng));

更换线路:

mMap.移动摄像头(摄像头更新工厂。新LATLNGZOOM(latLng,10.2f))

与:

mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng))