创建 Android 位置对象
我正在使用 Geocoder 类通过以下代码获取多个位置对象:
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 内,我尝试动态创建位置对象以添加到数组中;
如何创建空白位置对象?
I am using the Geocoder class to fetch multiple location objects by using the following code:
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);
}
In addition, inside the forloop, I am trying to dymanically create location objects to add to an array;
How can I create blank location objects ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您引用
android.location.Location
使用构造函数,该构造函数接受提供程序字符串并将其设置为您想要的任何内容。Assuming you refer to
android.location.Location
use the constructor which takes a provider string and set it to whatever you want.这并不是它的真正用途,如果您想在谷歌地图上绘制内容,您可能需要查看 GeoPoint 类。处理 Map OverlayItem 对象。您打算如何处理 Location 对象?此外,您还应该在线程或 AsyncTask 中执行 getFromLocation 调用,因为它正在执行远程服务器调用。
使用 GeoPoint 类。
这些值为 * 1000000,因为 GeoPoint 需要 E6 值。还要意识到,如果没有匹配项,则数组的长度可能为 0。
That's not really what it's intended for, if you are looking to plot stuff on a google map you may want to look into the GeoPoint class. You must use the GeoPoint class when dealing with Map OverlayItem objects. What do you plan to do with the Location objects? Also you should do the getFromLocation call in a thread or AsyncTask since it is doing a remote server call.
using the GeoPoint class.
The values are * 1000000 because the GeoPoint wants E6 values. Also realize that if there are no matches the array may be length 0.