- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在 Android 谷歌地图上移动相机时遇到了一些问题。
我有这个功能:
protected void centralizeMapToBounds(final LatLng southwest, final LatLng northeast, final LatLng taxi) {
final int padding = 30;
Location loc1 = new Location("");
loc1.setLatitude(southwest.latitude);
loc1.setLongitude(southwest.longitude);
Location loc2 = new Location("");
loc2.setLatitude(northeast.latitude);
loc2.setLongitude(northeast.longitude);
Location loc3 = new Location("");
loc3.setLatitude(taxi.latitude);
loc3.setLongitude(taxi.longitude);
float d1 = loc1.distanceTo(loc2);
float d2 = loc1.distanceTo(loc3);
float d3 = loc2.distanceTo(loc3);
LatLngBounds bounds = null;
try {
if(d1 > d2){
if(d1 > d3){
ICabDebug.i(TAG, "Maior distancia d1: " + d1);
if(southwest.latitude > northeast.latitude)
bounds = new LatLngBounds(southwest,northeast);
else
bounds = new LatLngBounds(northeast, southwest);
}else{
ICabDebug.i(TAG, "Maior distancia d3: " + d3);
if(northeast.latitude > taxi.latitude)
bounds = new LatLngBounds(northeast, taxi);
else
bounds = new LatLngBounds(taxi,northeast);
}
}else{
ICabDebug.i(TAG, "Maior distancia d2: " + d2);
if(southwest.latitude > taxi.latitude)
bounds = new LatLngBounds(southwest, taxi);
else
bounds = new LatLngBounds(taxi, southwest);
}
}catch (Exception e) {
ICabDebug.i(TAG, e.getMessage());
ICabDebug.i(TAG, "bounds = null");
bounds = null;
}
final LatLngBounds bounds2 = bounds;
// Pan to see all markers in view.
try {
ICabDebug.i(TAG, "Entro aki no primeiro bounds");
googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding));
}
catch (Exception e) {
if (mapView.getViewTreeObserver().isAlive()) {
mapView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@SuppressLint("NewApi")
@Override
public void onGlobalLayout() {
mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
try {
ICabDebug.i(TAG, "northeast ["+ bounds2.northeast.latitude + " / " + bounds2.northeast.longitude + "]");
ICabDebug.i(TAG, "southwest ["+ bounds2.southwest.latitude + " / " + bounds2.southwest.longitude + "]");
googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds2, padding));
}
catch (Exception ee) {
ICabDebug.i(TAG, "----------------------------");
ICabDebug.i(TAG, ee.getMessage());
ICabDebug.i(TAG, "----------------------------");
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(taxi, 15));
}
}
});
}
}
}
当我将它与坐标一起使用时,效果完美:(-23.5804166,-46.681909)(-23.4850942,-46.5802326)(-23.5802881,-46.6819049)
但是当我使用下面的坐标时,它会将相机移动到澳大利亚:(-23.5792416,-46.63472729999999)(-23.5436503,-47.4519223)(-23.580264,-46.6818923)
有人可以帮助我吗?谢谢
最佳答案
不确定您想使用问题中的代码实现什么。有点乱。
如果您想要显示包含 3 个 LatLng 的区域,您最好使用
LatLngBounds bounds = LatLngBounds.builder().include(latLng1).include(northeast).include(taxi).build();
map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding));
这将用几行代码替换所有的 ifs 和 try-catches。
顺便说一句。您不应该在代码中进行 try catch 。编程错误不是您捕获并尝试不同的东西,而是更改代码。
关于android - CameraUpdateFactory.newLatLngBounds 一直不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16367556/
我有一个在 Android 市场上相当流行的应用程序,它允许数以万计的用户按下一个按钮并向它发出语音命令。然后我就可以做很多不同的事情,比如给他们提供当前的天气预报等等...... 无论如何,我的应用
令人惊讶的是,标题基本上解释了它。我们有一个我们的客户制作的页面,我们正在重新创建该页面。 页面高度会一直增加,直到(我假设是这样)浏览器达到它的极限。我已经尝试过 Firebug 和 W3 验证器,
我是 react-native 的新手,试图创建我自己的组件,但它一直显示一个空屏幕。 这是我的组件代码 class BoxComponent extends Component { cons
我正在为我的 PHP 元素创建一个非常简单的博客,但遇到了一个简单的问题。我无法让我的页眉图像一直 float 。我有一个横幅,左边有一些文字,我有一个 1px 的切片,在可以选择的任何分辨率的宽度上
为什么我可以在另一个 Controller 的 View 中访问一个 Controller 的辅助方法?有没有办法在不破解/修补 Rails 的情况下禁用它? 最佳答案 @George Schreib
我正在使用带有最新 ADT 插件的 Eclipse Kepler SP2。每隔一分钟 Eclipse 就会说“为 Android 4.4.2 加载数据”并阻止我想做的一切。我在不同的文件夹中有几个 E
我是一名优秀的程序员,十分优秀!