地理编码例如不工作 [英] Geocoding example not working
本文介绍了地理编码例如不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个简单的地理编码的应用,但它不是working.I给予一切必要的permissions.Please有人告诉我在哪里,我在去提前wrong.Thanx。
公共类ForgeocdingActivity延伸活动{
地理codeR GC;
/ **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
最终的EditText ED =(EditText上)findViewById(R.id.editText1);
按钮B1 =(按钮)findViewById(R.id.button1);
。最后弦乐to_add = ed.getText()的toString();
b1.setOnClickListener(新OnClickListener(){ @覆盖
公共无效的onClick(查看arg0中)
{
尝试
{
清单<地址>地址2 = gc.getFromLocationName(to_add,3); 如果(地址2 =空&放大器;!&放大器; address2.size()大于0)
{
双LAT1 = address2.get(0).getLatitude();
双lng1 = address2.get(0).getLongitude();
Toast.makeText(getBaseContext(),纬度:+ LAT1 +经度:+ lng1,Toast.LENGTH_SHORT).show();
}
}
赶上(例外五)
{
e.printStackTrace();
}
}
}); }
}
解决方案
请在下面写code为
地理codeR地理codeR =新的地缘codeR(这一点,Locale.getDefault());
清单<地址>地址=地理coder.getFromLocation(currentlat,currentlng,1);
现在地址的列表包含最接近的已知领域和测试这个code到真实的设备。
I have written a simple geocoding application but it is not working.I have given all necessary permissions.Please someone tell me where i am going wrong.Thanx in advance.
public class ForgeocdingActivity extends Activity {
Geocoder gc;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText ed=(EditText)findViewById(R.id.editText1);
Button b1=(Button)findViewById(R.id.button1);
final String to_add = ed.getText().toString();
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0)
{
try
{
List<Address> address2 = gc.getFromLocationName(to_add,3);
if(address2 != null && address2.size() > 0)
{
double lat1 = address2.get(0).getLatitude();
double lng1 = address2.get(0).getLongitude();
Toast.makeText(getBaseContext(), "Lat:"+lat1+"Lon:"+lng1, Toast.LENGTH_SHORT).show();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
}
}
解决方案
Please write below code for that
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(currentlat, currentlng, 1);
Now the list of Address contains the closest known areas and test this code into real device.
这篇关于地理编码例如不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文