我正在使用Geocoder类通过以下代码获取多个location对象:
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 3);
Address[] addresses_array = new Address[addresses.size()];
addresses.toArray(addresses_array);
for( int i = 0; i < addresses_array.length; i++ ){
//create location object here
locOBJ.setLatitude(LATITUDE);
locOBJ.setLongitude(LONGITUDE);
}此外,在forloop内部,我尝试动态地创建location对象以添加到数组中;
如何创建空白位置对象?
发布于 2011-02-09 21:49:51
假设您引用的是android.location.Location,请使用构造函数,该函数接受提供者字符串并将其设置为您想要的任何值。
发布于 2011-02-09 22:03:08
这并不是它的真正目的,如果你想在谷歌地图上绘制一些东西,你可能想看看GeoPoint类。在处理地图OverlayItem对象时,必须使用GeoPoint类。您计划如何处理Location对象?此外,您应该在线程或AsyncTask中执行getFromLocation调用,因为它正在执行远程服务器调用。
使用GeoPoint类。
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 3);
int size = addresses.size();
GeoPoint gp[] = new GeoPoint[size];
for(int i = 0; i<size; i++) {
Address addr = addresses.get(i);
gp[i] = new GeoPoint(addr.getLatitude()*1000000,
address.getLongitude()*1000000);
}这些值是* 1000000,因为GeoPoint需要E6值。还要认识到,如果没有匹配,则数组的长度可能为0。
https://stackoverflow.com/questions/4945697
复制相似问题