【发布时间】:2016-07-02 08:53:24
【问题描述】:
我试图抓取一个网站来获取 lat,lng 使用 Jsoup 放入 gmaps 但我得到了一个堆栈跟踪
FATAL EXCEPTION: main
Process: au.com.industryresponsetraining.map, PID: 18842
java.lang.NumberFormatException: Invalid double: ""
因为
您正在解析 onCreate() 值而没有放置任何默认值,因此异常
除了我的 onCreate() 是我的 Jsoup 运行的地方。 如果我添加类似
double myDouble;
String myString = ((EditText) findViewById(R.id.editText1)).getText().toString();
if (myString != null && !myString.equals("")) {
myDouble = Double.valueOf(myString);
} else {
myDouble = 0;
}
引用自 here 我的地图在海上结束。
我的网页上有一个有效的 lat,lng
这是我的活动
package au.com.industryresponsetraining.map;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
String ln = "";
String lt = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
new Thread(new Runnable() {
@Override
public void run() {
try {
//get the Document object from the site. Enter the link of site you want to fetch
Document document = Jsoup.connect("http://www.industryresponsetraining.com.au/mdt/lat.html").get();
//Get the title of blog using title tag
//title = document.select("p").text().toString();
lt = document.select("h6").text().toString();
ln = document.select("h7").text().toString();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
double lats = Double.valueOf(lt);
double lngs = Double.valueOf(ln);
LatLng marker = new LatLng(lats, lngs);
mMap.addMarker(new MarkerOptions().position(marker).title("my Marker"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(marker));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(marker, 15));
}
}
实际的谷歌地图资料已参考developers页面
【问题讨论】:
-
在onMapReady中记录ln和lt的值。还要记录线程中的值,您将知道发生了什么或使用调试器
-
@IntelliJ Amiya 我已经阅读了那篇文章,甚至提到了类似的东西并给出了结果。没用
-
@Raghunandan 我会把它记录为
lt = document.select("h6").text().toString();并从上面删除它吗?
标签: android google-maps android-studio google-maps-api-3