获取当前位置GMaps实现。 [英] Get Current Location GMaps
问题描述
我试图为Android不少获取当前位置的。但我认为他们大多是过时的,或者我只是不明白这一点。
我不想设定一个marker.addmarker(PARAMS ..)我想用蓝色的点默认为我的GMaps实现位置。在这里,我发现有关财产以后,但我的坏,也AINT的工作。
<一个href=\"http://stackoverflow.com/questions/17003362/customize-marker-of-mylocation-google-maps-v2-android\">Customize myLocation谷歌地图Android版V2的标记
因此,在第一线,我需要,当我的位置被更新我的当前位置与监听器。我试着现在这个权利(测试在真实设备上)。但myLocation总是= NULL。
//获取GMaps实现片段
MMAP =((MapFragment)getFragmentManager()findFragmentById(R.id.map)。)的GetMap();
mMap.setMyLocationEnabled(真); //激活蓝点 myLocation = mMap.getMyLocation(); //测试,但没有工作= NULL //使用的LocationManager尝试
locManager =(的LocationManager)getSystemService(this.LOCATION_SERVICE);
标准标准=新标准();
字符串提供商= locManager.getBestProvider(标准,真正的); myLocation = locManager.getLastKnownLocation(供应商);
如果(myLocation!= NULL){
双纬度= myLocation.getLatitude();
双LON = myLocation.getLongitude();
} locManager.requestLocationUpdates(供应商,1000,0,新LocationListener的(){
@覆盖
公共无效onLocationChanged(地点){
myLocation =位置;
} @覆盖
公共无效onStatusChanged(字符串提供商,INT地位,捆绑演员){ } @覆盖
公共无效onProviderEnabled(字符串提供商){ } @覆盖
公共无效onProviderDisabled(字符串提供商){ }
});
按照以下的 http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/ 。然后,只需把你在你的谷歌地图(使用gps.getLatitude(),gps.getLongitude())的纬度和经度,它会显示你的当前位置。
i tried a lot of "get current location" for android. But i think most of them are outdated, or i simply dont get it.
I DONT want to set a marker.addmarker(params..) i would like to use the blue default dot for my position on Gmaps. Here i've found somthing about that, but for my bad it also aint work.
Customize marker of myLocation Google Maps v2 Android
So in first line i need, my current Location with a Listener when my Location is updating. Im trying this right now (Testing on a real device). But myLocation is always =null.
//get GMaps Fragment
mMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.setMyLocationEnabled(true); //activate Blue dot
myLocation = mMap.getMyLocation(); //Testing, but not working = null
//Trying with LocationManager
locManager =(LocationManager)getSystemService(this.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locManager.getBestProvider(criteria, true);
myLocation = locManager.getLastKnownLocation(provider);
if(myLocation != null){
double lat = myLocation.getLatitude();
double lon = myLocation.getLongitude();
}
locManager.requestLocationUpdates(provider, 1000, 0, new LocationListener() {
@Override
public void onLocationChanged(Location location) {
myLocation = location;
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
});
Follow this http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/ . Then just place the latitude and longitude you get(using gps.getLatitude(), gps.getLongitude()) in your google map and it will show your current location.
这篇关于获取当前位置GMaps实现。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!