Creating Android Location Object

你说的曾经没有我的故事 提交于 2019-12-03 04:51:34

Assuming you refer to android.location.Location use the constructor which takes a provider string and set it to whatever you want.

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.

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);
}

The values are * 1000000 because the GeoPoint wants E6 values. Also realize that if there are no matches the array may be length 0.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!