[英]How to get address using longitude and latitude
I am using Geocoding .I want to get address or location using longitude and latitude .But when I used bedford .It is showing Atlantic ocean every time. 我正在使用地理编码。我想使用经度和纬度来获取地址或位置。但是当我使用Bedford时 ,每次都显示大西洋 。
package mypackage;
import javax.microedition.location.AddressInfo;
import javax.microedition.location.Landmark;
import net.rim.device.api.lbs.Locator;
import net.rim.device.api.lbs.LocatorException;
import net.rim.device.api.system.Application;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
public class myReverseGeocode extends MainScreen
{
private Thread reverseGeocode;
public myReverseGeocode()
{
reverseGeocode = new Thread(thread);
reverseGeocode.setPriority(Thread.MIN_PRIORITY);
reverseGeocode.start();
}
Runnable thread = new Runnable()
{
public void run()
{
AddressInfo addrInfo = null;
int latitude = (int)(52.135973);
int longitude = (int)(-0.466655);
try
{
Landmark[] results = Locator.reverseGeocode
(latitude, longitude, Locator.ADDRESS );
if ( results != null && results.length > 0 )
addrInfo = results[0].getAddressInfo();
synchronized(Application.getEventLock())
{
add(new LabelField("------------------------"+addrInfo));
add(new LabelField("------------------------"+addrInfo.getField(addrInfo.BUILDING_FLOOR)));
add(new LabelField("------------------------"+addrInfo.getField(addrInfo.CITY)));
add(new LabelField("------------------------"+addrInfo.hashCode()));
add(new LabelField("------------------------"+addrInfo.getField(addrInfo.BUILDING_NAME)));
add(new LabelField("------------------------"+addrInfo.getField(addrInfo.COUNTRY)));
add(new LabelField("------------------------"+addrInfo.getField(addrInfo.STREET)));
}
// add(new LabelField("---"+addrInfo));
}
catch ( LocatorException lex )
{
synchronized(Application.getEventLock())
{
System.out.print("EVENT THREAD\n");
Dialog.inform("Posted!"+lex);
}
}
}
};
}
That reverseGeocode method takes two ints as parameters, but these are " decimal degrees to five decimal places, multiplied by 100000 " according to the docs. 根据文档,那个reverseGeocode方法采用两个整数作为参数,但是它们是“ 十进制小数到五个小数位,再乘以100000 ”。
Just create a new Coordinates
instance and use the second version of that method: 只需创建一个新的Coordinates
实例并使用该方法的第二个版本:
Coordinates coords = new Coordinates(52.135973, -0.466655, 0);
Landmark[] results = Locator.reverseGeocode(coords, Locator.ADDRESS );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.