Google地图精简模式将相机移动到经纬度边界会添加不需要的地图填充 [英] Google Map Lite Mode moveCamera to lat lng bounds adds unwanted map padding

查看:120
本文介绍了Google地图精简模式将相机移动到经纬度边界会添加不需要的地图填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让地图相机移动到我的LatLngBounds。因此,我在 BaseExpandableListAdapter getChildView onMapReady 我将 moveCamera 改为 LatLngBounds

 @Override 
public View getChildView(final int groupPosition,int childPosition,boolean isLastChild,View convertView,ViewGroup parent){

convertView = inflater.inflate( R.layout.event_child,parent,false);

GoogleMapOptions options = new GoogleMapOptions();
options.liteMode(true)
.compassEnabled(false)
.mapToolbarEnabled(false)
.rotateGesturesEnabled(false)
.tiltGesturesEnabled(false)
.scrollGesturesEnabled(false)
.zoomControlsEnabled(false)
.zoomGesturesEnabled(false);

SupportMapFragment mapFragment = SupportMapFragment.newInstance(options);
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.add(R.id.event_fragment_map,mapFragment,event_fragment_map)。commit();

mapFragment.getMapAsync(new OnMapReadyCallback(){
@Override
public void onMapReady(GoogleMap googleMap){
mGoogleMap = googleMap;
moveMapAddBounds() ;
}
});




private void moveMapAddBounds(){
mGoogleMap.addPolygon(new PolygonOptions()。add(getLatLngBounds() .south)
.add(new LatLng(getLatLngBounds()。northeast.latitude,getLatLngBounds()。southwest.longitude))
.add(getLatLngBounds()。northeast)
.add( new LatLng(getLatLngBounds()。southwest.latitude,getLatLngBounds()。northeast.longitude))
);
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(getLatLngBounds(),0));
}

public LatLngBounds getLatLngBounds(){
//随机伪造的latlng和距离
LatLng from = new LatLng(51.1113564,17.0041787);
double distance = 1717.906494140625;
返回新的LatLngBounds.Builder()。
包括(SphericalUtil.computeOffset(from,distance,0))。
包括(SphericalUtil.computeOffset(from,距离,90))。
包括(SphericalUtil.computeOffset(from,distance,180))。
include(SphericalUtil.computeOffset(from,distance,270))。build();
}

我按照


I want map camera to move to my LatLngBounds. So I add map fragment to layout in BaseExpandableListAdapter's getChildView and onMapReady I'll moveCamera to LatLngBounds

@Override
public View getChildView(final int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {

    convertView = inflater.inflate(R.layout.event_child, parent, false);

    GoogleMapOptions options = new GoogleMapOptions();
    options.liteMode(true)
           .compassEnabled(false)
           .mapToolbarEnabled(false)
           .rotateGesturesEnabled(false)
           .tiltGesturesEnabled(false)
           .scrollGesturesEnabled(false)
           .zoomControlsEnabled(false)
           .zoomGesturesEnabled(false);

    SupportMapFragment mapFragment = SupportMapFragment.newInstance(options);
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.add(R.id.event_fragment_map, mapFragment, "event_fragment_map").commit();

    mapFragment.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(GoogleMap googleMap) {
            mGoogleMap = googleMap;
            moveMapAddBounds();
        }
    });

//...
}

private void moveMapAddBounds(){
    mGoogleMap.addPolygon(new PolygonOptions().add(getLatLngBounds().southwest)
                                              .add(new LatLng(getLatLngBounds().northeast.latitude, getLatLngBounds().southwest.longitude))
                                              .add(getLatLngBounds().northeast)
                                              .add(new LatLng(getLatLngBounds().southwest.latitude, getLatLngBounds().northeast.longitude))
                         );
    mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(getLatLngBounds(), 0));
}

public LatLngBounds getLatLngBounds() {
    //random fake latlng and distance
    LatLng from = new LatLng(51.1113564, 17.0041787);
    double distance = 1717.906494140625;
    return new LatLngBounds.Builder().
            include(SphericalUtil.computeOffset(from, distance, 0)).
            include(SphericalUtil.computeOffset(from, distance, 90)).
            include(SphericalUtil.computeOffset(from, distance, 180)).
            include(SphericalUtil.computeOffset(from, distance, 270)).build();
}

I'm calculating bounds according to http://googlemaps.github.io/android-maps-utils/ and it seems to work OK as the rectangle added to map in moveMapAddBounds is added in valid positions but the map camera is moved to almost good position with the exception that it adds a random (?) paddings to map (symmetric above and below the rectangle) as seen on picture:

I've observed that those paddings are always the same for a particular LatLngBounds but they differ between different LatLngBounds.

解决方案

The reason was I used Lite Mode where only integer zooms are available.

http://code.google.com/p/gmaps-api-issues/issues/detail?id=7573&q=apitype%3AAndroid2%20type%3ADefect&sort=-id%20-stars&colspec=ID%20Type%20Status%20Introduced%20Fixed%20Summary%20Internal%20Stars

这篇关于Google地图精简模式将相机移动到经纬度边界会添加不需要的地图填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆