- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试在 mapbox 中定位一个点,该点每 30 秒使用服务器数据更新其位置。我该怎么做呢?我使用的是 7.0.1 版。到目前为止,我已经设法显示了一个标记,但我无法在运行时更改它的位置。标记正在接受来自服务器的数据,但仅在它启动时。
我尝试了以下代码,但是当我尝试运行它时我的模拟器崩溃了:
package com.example.susmi.rubus;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.mapbox.geojson.Feature;
import com.mapbox.geojson.FeatureCollection;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.Style;
import com.mapbox.mapboxsdk.style.layers.PropertyFactory;
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class Main2Activity extends AppCompatActivity {
private MapView mapView;
String lat = "xx", lon = "xy";
MapboxMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this, getString(R.string.access_token));
setContentView(R.layout.activity_main2);
Bundle bundle = getIntent().getExtras();
String s = bundle.getString("xyz").toUpperCase();
String html = "https://rubus.arduinocommunity.org.bd/api/view_data.php?fbclid=IwAR0pyaB4ZDQhrwAJ99vqAdRmSgAgvpBpKwg4RkgIeJDLu6wiNvWqGCJqFbQ";
//The thread is only for parsing data from the server
Thread t = new Thread(() -> {
try {
int count = 0;
Document doc = Jsoup.connect(html).get();
Element body = doc.body();
Elements paragraphs = body.getElementsByTag("td");
for (Element para : paragraphs) {
String s2 = para.text().toUpperCase();
if (s2.equals(s)) {
count++;
} else if (count != 0)
count++;
if (count == 3) {
lat = s2;
} else if (count == 4) {
lon = s2;
}
}
} catch (Exception e) {
e.printStackTrace();
}
});
t.start();
try {
t.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
map = mapboxMap;
mapboxMap.setStyle(Style.LIGHT, new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
// Add the marker image to map
double s1 = Double.parseDouble(lat), t = Double.parseDouble(lon);
style.addImage("marker-icon-id",
BitmapFactory.decodeResource(
Main2Activity.this.getResources(), R.drawable.mapbox_marker_icon_default));
GeoJsonSource geoJsonSource = new GeoJsonSource("source-id", Feature.fromGeometry(
Point.fromLngLat(t, s1)));
style.addSource(geoJsonSource);
SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id");
symbolLayer.withProperties(
PropertyFactory.iconImage("marker-icon-id")
);
style.addLayer(symbolLayer);
updateMarker(s, html);
}
});
}
});
}
public void updateMarker(String s, String html) {
while(true) {
//The thread is only for parsing data from the server
Thread t1 = new Thread(() -> {
try{
Thread.sleep(3000);
}catch(InterruptedException e)
{
e.printStackTrace();
}
try {
int count = 0;
Document doc = Jsoup.connect(html).get();
Element body = doc.body();
Elements paragraphs = body.getElementsByTag("td");
for (Element para : paragraphs) {
String s2 = para.text().toUpperCase();
if (s2.equals(s)) {
count++;
} else if (count != 0)
count++;
if (count == 3) {
lat = s2;
} else if (count == 4) {
lon = s2;
}
}
} catch (Exception e) {
e.printStackTrace();
}
});
t1.start();
try{
t1.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
if (map.getStyle() != null) {
GeoJsonSource g = map.getStyle().getSourceAs("source-id");
if (g != null) {
g.setGeoJson(FeatureCollection.fromFeature(
Feature.fromGeometry(Point.fromLngLat(88, 24))//Double.parseDouble(lon), Double.parseDouble(lat)))
));
}
}
}
}
// Add the mapView's own lifecycle methods to the activity's lifecycle methods
@Override
public void onStart() {
super.onStart();
mapView.onStart();
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onStop() {
super.onStop();
mapView.onStop();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
}
最佳答案
问题在于,由于 updateMarker() 中的 while 循环,onStyleLoaded 方法从未完成,因此我的模拟器保持空白。感谢那些回答的人。
关于java - Mapbox SDK : Changing a marker position at runtime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54484424/
我在内存中有一个 Map 来存储我的对象。我想在内存不足时刷新内存。我现在正在这样做: void add(K key, V value) { if (underPressure()) {
我是 JBPM 的新手。我下载并开始使用 eclipse。然后我安装了 JBPM 插件和 Modeler 2.0 插件。当我创建一个新的 JBPM 项目时,它要求 JBPM 运行时。我在互联网上搜索了
我是 JBPM 的新手。我下载并开始使用 eclipse。然后我安装了 JBPM 插件和 Modeler 2.0 插件。当我创建一个新的 JBPM 项目时,它要求 JBPM 运行时。我在互联网上搜索了
我目前正在将Windows 8.1应用程序移植到Windows 10 UAP应用程序,该应用程序使用互操作在C++和C#之间进行通信,并且 pop 以下错误: $(ProjectName).Inter
我正在使用 Parcel 来捆绑我的项目并 Jest 运行我的测试。 一切正常,但在测试中我有 async/await关键字,我必须导入 regenerator-runtime/runtime像这样:
一旦我尝试使用 Promises,Browserify 就会抛出此错误。 在 中找不到模块“regenerator-runtime/runtime” 我尝试过 Node 版本 10.15.3 和 12
我目前正在试验 quarkus,找不到在运行时更改一些 openapi 信息的方法(这里,我希望授权 url 根据环境而改变)。 应该可以通过使用 OASFilter 并从环境变量中提供信息来实现,但
我正在使用 rust_bert 汇总文本。我需要使用rust_bert::pipelines::summarization::SummarizationModel::new设置模型,该模型可以从互联网
我正在 Visual Studio 中处理其中一个新的“类库(NuGet 包)”项目。一切都很顺利,直到前几天它开始引发有关 System.Runtime.Extensions 程序集的错误: Ass
我正在使用 tokio::runtime::current_thread::Runtime我希望能够在同一个线程中运行 future 并停止 react 堆。页面上的示例未显示如何停止运行时。有什么办
我找不到如何声明 runtime.LockOSThread()和 runtime.UnlockOSThread() .我将其定义为 [runtime.LockOSThread()] 一些代码 [run
我有这样的代码, Routine 1 { runtime.LockOSThread() print something send int to routine 2 runtime.UnlockOSTh
我正在尝试执行此操作:当我单击“搜索”按钮时,命令提示符窗口打开。 我尝试使用ProcessBuilder,没有出现错误,但是不起作用。你能帮我一下吗? package sys.tool; impor
我的应用程序运行大约 4 小时后出现此错误。我不知道为什么会这样。该错误发生在 windows 7 和 windows XP 系统上。抱歉,我没有更多信息。我的应用程序运行大约 4 次后才收到此错误消
我收到错误:“此程序集是由比当前加载的运行时更新的运行时构建的,无法加载。” 我有一个 .NET 2.0 项目调用的 .NET 4.0 dll 项目。有没有办法调和框架的差异? 最佳答案 I have
我有一个 WIX 安装程序,它在安装过程中执行自定义操作。当我运行 WIX 安装程序并遇到它的第一个自定义操作时,安装程序失败,我在 MSI 日志中收到如下错误: Action start 12:
我正在尝试提交 spark 作业 它是这样开始的: import javax.xml.parsers.{SAXParser, SAXParserFactory} import org.apache.s
我正在做一些 WCF 工作,但我不明白为什么会遇到这个错误。 System.Runtime.Serialization.DataContractAttribute命名空间中不存在 System.Run
我尝试按照 this 在 React 应用程序中使用 async/await : 目前,我正在运行webpack --config webpack.dev.config.js --watch --pr
我已经从托管的 Window Server 2008 下载了已发布的(代码隐藏文件不存在,与 bin 文件夹中的 dll 结合)Web 应用程序,并在调试该应用程序时使用 Visual Studio
我是一名优秀的程序员,十分优秀!