- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我一直在 Google 和 SO 上对此进行研究,但我被卡住了,我想我遗漏了一些基本的东西。大多数examples我见过不处理任意 mapWidth 和单个点,只处理 Overlay 的跨度。
我有一个 map 点数据库、一个MapView
和一个Geocoder
。我可以在我的应用程序中搜索邮政编码,并让我的 Geocoder
返回一个 Address
。
使用此 Address
,我可以构建一个 GeoPoint
并搜索我的数据库并获取附近点的列表。问题来自尝试使用从返回的 Address
点和到数据库中最近点的距离构造的跨度来 zoomToSpan。
我只希望跨度包含最近的两点(如果可用)。这是相关代码:
Collections.sort(listingDisplay, mComparator);
listingDisplayAdapter.notifyDataSetChanged();
float spanWidth =0;
if (listingDisplay.size() > 1) {
spanWidth = (float) (2 * distanceFromPoint(listingDisplay.get(1),
current));
} else if (listingDisplay.size() == 1) {
spanWidth = (float) (2 * distanceFromPoint(listingDisplay.get(0),
current));
}
Log.v(TAG, "SpanWidth: " + spanWidth);
// Create span
int minLat = (int) (current.getLatitudeE6() - (spanWidth * 1E6) / 2);
int maxLat = (int) (current.getLatitudeE6() + (spanWidth * 1E6) / 2);
int minLong = (int) (current.getLongitudeE6() - (spanWidth * 1E6) / 2);
int maxLong = (int) (current.getLongitudeE6() + (spanWidth * 1E6) / 2);
// Zoom against span. This appears to create a very small region that doesn't encompass the points
mapController.setCenter(current);
mapController.zoomToSpan(Math.abs( minLat - maxLat ), Math.abs( minLong - maxLong ));
ListingDisplay
包含最近点的列表,带有比较器,mComparator
使用最接近我返回的 Address
的位置对列表进行排序( GeoPoint
名为:current
) 在列表的顶部。
然后我根据最接近的值设置 spanWidth
的值,并尝试从中计算出跨度。
我的问题是,如何从给定的距离和中心点构建跨度?
最佳答案
经过非常非常长的时间后,我终于意识到我没有考虑一些重要信息,其中主要是 Android 上的距离是使用 WGS84 椭球计算的。
我最终使用了 Jan Matuschek's excellent and simple GeoLocation class 中的辅助方法,其中对所涉及的概念进行了非常的详尽解释。
我的方法基本上可以归结为以下几点。它可能可以进行很多优化,直到一个简单的 SQL 查询,但这里是为了我的目的,其中 listingDisplay
是数据库检索的自定义 LocationNode
对象的数组,并且 GeoPoint
当前是直接从标准 Android Geocoder 返回的 Address
创建的。
public void setRegionForGeoPoint(GeoPoint current) {
// Earth radius in KM
final double EARTH_RADIUS = 6371.01;
// Dummy span distance in KM for initial search; distance buffer is in M
final double DISTANCE_BUFFER = 50;
final double dummyDistance = 100.0;
//Create a list to store distances
List<Double> distancesList = new ArrayList<Double>();
// Loop through and modify LocationNodes with distance from user
for (LocationNode location : listingDisplay) {
location.setDistance((float) distanceFromUser(location));
// Dynamically calculate distance from our current point (epicentre)
distancesList.add(distanceFromPoint(location, current));
}
// Sort distances
Collections.sort(distancesList);
// Calculate regional span
float spanWidth = (float) dummyDistance;
double distance = 0;
if (distancesList.size() > 0) {
if (distancesList.size() > 1) {
distance = distancesList.get(1);
spanWidth = (float) (distance + DISTANCE_BUFFER);
} else if (distancesList.size() == 1) {
distance = distancesList.get(0);
spanWidth = (float) (distance + DISTANCE_BUFFER);
}
//Obtain the spanwidth in metres.
double spanWidthInKM = (double) spanWidth / 1000;
// Create span
GeoLocation[] boundingBoxSpan = currentGeoLocation
.boundingCoordinates(spanWidthInKM, EARTH_RADIUS);
//Create min/max values for final span calculation
int minLatSpan = (int) (boundingBoxSpan[0].getLatitudeInDegrees() * 1E6);
int maxLatSpan = (int) (boundingBoxSpan[1].getLatitudeInDegrees() * 1E6);
int minLongSpan = (int) (boundingBoxSpan[0].getLongitudeInDegrees() * 1E6);
int maxLongSpan = (int) (boundingBoxSpan[1].getLongitudeInDegrees() * 1E6);
//Finally calculate span
int latSpanE6 = Math.abs(minLatSpan - maxLatSpan);
int lonSpanE6 = Math.abs(minLongSpan - maxLongSpan);
// Set center
mapController.setCenter(current);
// Zoom to span
mapController.zoomToSpan(latSpanE6, lonSpanE6);
} else {
//TODO: Handle the case when we have no distance values to use
}
}
public double distanceFromPoint(LocationNode location, GeoPoint point) {
// Calculate distance from user via result
Location locationA = new Location("point A");
locationA.setLatitude(location.getLatitude());
locationA.setLongitude(location.getLongitude());
Location locationB = new Location("point B");
locationB.setLatitude((double) (point.getLatitudeE6() / 1E6));
locationB.setLongitude((double) (point.getLongitudeE6() / 1E6));
double distance = locationA.distanceTo(locationB);
Log.v(TAG, "Calculated Distance: " + distance);
return distance;
}
关于Android:MapController.zoomToSpan:给定距离和中心点的跨度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9424406/
这就是我现在正在做的事情。我在设计中使用 LESS CSS。我需要在指定输入之间放置 2 个跨度。所有元素的宽度都应为 100%。跨度应始终为 20px 宽度输入宽度可以根据屏幕宽度进行更改。谁能帮帮
我有一个包含文本和输入字段的跨度。我想知道是否可以让文本左对齐,输入字段右对齐。 NAME: .textBox{ display:inline-block; width:450px
我有这个按钮,我想让它在我点击“选择”时调用方法,在我点击“更改”时调用另一个方法: Select Change 我尝试输入 (click)="method()",但没有成功。我很
我正在开发聊天应用程序 (cordova),当我要在无法输入的表情符号后输入文本时,我在这段代码中遇到了问题 https://output.jsbin.com/radaref This i
很抱歉,如果这是一个非常愚蠢的问题,但我是一名开发人员,目前我的设计技能很少,我在个人网站上工作并且遇到了一个小问题。 我有一个带 ul 的顶部导航和 li元素。这些元素包含链接 . 跨度仅在链接悬
fiddle :https://jsfiddle.net/burz4g8s/4/ 我的 HTML 包含多行双按钮对。服务器端应用程序在 JSP 循环中输出按钮,所以我无法控制各个按钮——我不能使用 d
TextView.setLetterSpacing允许设置字母间距/字符间距。 有没有对应的CharacterStyle / span class允许在 TextView? 中的文本子集上设置字母间距
如何使洋红色矩形比红色矩形短 6 倍? GridLayout { id: gridLayout anchors.fill: parent flo
我最近开始使用 Twitter Bootstrap,但我似乎无法理解 span 的作用以及为什么会有不同的编号 span,例如 span4、span12?什么是偏移量以及它们何时使用? (有时与跨度一
我正在尝试构建一个 jQuery 函数来计算跨度中的总数 var sumnormaltotal = 0; $('span[id^="normaloffertotalspan"]').each(func
我想知道haskell如何评估以下表达式。 span (`elem` ['A'..'Z']) "BOBsidneyMORGANeddy" 结果是 ("BOB","sidneyMORGANeddy")
我有三个词,我想在第一个空格之后的内容周围添加一个跨度,所以 hello world 变成: hello world 和: hello world again 变成: hello world agai
我正在寻找纯 CSS 解决以下问题的方法。 考虑以下 HTML: Some text Some text 两者都是 正在显示元素 inline-block .如何在第二个 的左侧
如何将 Span 放置在其容器的底部? 我目前拥有的:http://jsfiddle.net/wRbax/2/ 我希望 .box 始终位于 .td 的底部 CSS .td { vertical
我试图在 li 中 float 两个 span。左跨度将有我的标签,在右跨度内我将构建一个具有嵌套跨度的图形。我有基本结构,但 chrome 将数字放在左侧跨度的末尾。我该如何解决这个问题? HTML
我有一个像这样的 JavaScript 变量: var text = "A businessman should be able to manage his business matters"; 我想
一些内容可编辑的框与其他框重叠,因此并非所有框都是可编辑的。我想保留与跨度位置中心对齐的文本,如下所示。我如何实现这一点? span { margin: auto; text-alig
我正在使用 WYSIWYG (InnovaEditor) 来编辑我网站上的内容,它适用于 Chrome、IE,主要适用于 Firefox,但 FF 有一个稍微令人讨厌的问题。我将 span 标签插入到
这是我的 html: Settings Export Import 和CSS: span.button { float:right; margin-righ
这里是问题所在:http://jsfiddle.net/STG22/3/ 我希望 span 不会分成两个不同的行(就像上面示例中的第三行一样)。我该怎么做? CSS: span { backg
我是一名优秀的程序员,十分优秀!