问题描述
- Geocode 没有返回值的问题
-
我想把地址转换成long和纬度型,但是它返回0。请大家帮我看看错误出现在哪里?
代码如下:geocoder = new Geocoder(this); buttonSave.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { try { EditText loc = (EditText)findViewById(R.id.txtAddress); String locationName = loc.getText().toString(); List<Address> addressList = geocoder.getFromLocationName(locationName, 2); if(addressList!=null && addressList.size()>0) { lat = (int)(addressList.get(0).getLatitude()*1000000); lng = (int)(addressList.get(0).getLongitude()*1000000); } } catch (IOException e) { e.printStackTrace(); } lattitude = Integer.toString(lat); longertude = Integer.toString(lng);
LOGCAT:
06-10 13:44:28.799: I/System.out(274): [INFO:19529614]: LogSource: Running flush 06-10 13:44:28.799: I/System.out(274): [INFO:19529623]: LogSource: Sending payload [bytes=267] 06-10 13:44:32.262: D/SntpClient(83): request time failed: java.net.SocketException: Address family not supported by protocol 06-10 13:44:33.809: I/System.out(274): [INFO:19534623]: LogSource: Running delayed flush 06-10 13:44:33.809: W/System.err(2517): java.io.IOException: Unable to parse response from server 06-10 13:44:33.823: I/System.out(274): [INFO:19534640]: LogSource: Running flush 06-10 13:44:33.829: I/System.out(274): [INFO:19534651]: LogSource: Sending payload [bytes=267] 06-10 13:44:33.869: W/System.err(2517): at android.location.Geocoder.getFromLocationName(Geocoder.java:178) 06-10 13:44:33.869: W/System.err(2517): at de.vogella.android.locationapi.simple.InsertStock$1.onClick(InsertStock.java:108) 06-10 13:44:33.879: W/System.err(2517): at android.view.View.performClick(View.java:3110) 06-10 13:44:33.891: W/System.err(2517): at android.view.View$PerformClick.run(View.java:11928) 06-10 13:44:33.899: W/System.err(2517): at android.os.Handler.handleCallback(Handler.java:587) 06-10 13:44:33.899: W/System.err(2517): at android.os.Handler.dispatchMessage(Handler.java:92) 06-10 13:44:33.899: W/System.err(2517): at android.os.Looper.loop(Looper.java:132) 06-10 13:44:33.913: W/System.err(2517): at android.app.ActivityThread.main(ActivityThread.java:4025) 06-10 13:44:33.919: W/System.err(2517): at java.lang.reflect.Method.invokeNative(Native Method) 06-10 13:44:33.939: W/System.err(2517): at java.lang.reflect.Method.invoke(Method.java:491) 06-10 13:44:33.939: W/System.err(2517): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 06-10 13:44:33.939: W/System.err(2517): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 06-10 13:44:33.939: W/System.err(2517): at dalvik.system.NativeStart.main(Native Method)
解决方案
你代码明明转换成int。
不需要强制转换为int
时间: 2024-11-05 02:33:25