如何在谷歌地图获取当前位置使用地图视图 [英] How to get current location on google maps using map view
问题描述
我想知道怎样才能让我使用地图视图谷歌地图的当前位置。这就是当我走,并从一个位置到其他移动,我在地图上的位置也将被改变。它将由GPS或网络提供商来实现,但想找到自己合适的当前位置。
I want to know that how I can get my current position on google maps using map view. That is when I walk and move from one location to other so my location on maps will also be changed. It will be achieved by GPS or by Network Provider but want to get my appropriate current location.
推荐答案
您必须实现位置监听器来获取经纬度数据,使用这些值设定在谷歌地图上的位置,并使用一个标记,以表明这一立场。
you must implement Location Listener to get the latitude and longitude data,using those values set the position on google map and use a marker to indicate that position
public class MyLocationListener implements LocationListener {
protected LocationManager lm;
public String message="Hello";
Location location;
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1;
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000000;
Context mContext;
public MyLocationListener(Context mContext) {
// TODO Auto-generated constructor stub
this.mContext = mContext;
String context=Context.LOCATION_SERVICE;
lm = (LocationManager)mContext.getSystemService(context);
lm.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER,MINIMUM_TIME_BETWEEN_UPDATES,MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,this);
}
public void showCurrentLocation()
{
location=lm.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
if (location != null) {
message = String.format(
"Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
t1.setText(message);
}
}
public void onLocationChanged(Location location)
{
/* String message = String.format(
"New Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
t1.setText(message);
Toast.makeText(WinUirep.this,
"Location Changed !",
Toast.LENGTH_LONG).show();*/
}
public void onStatusChanged(String s, int i, Bundle b)
{
}
public void onProviderDisabled(String s)
{
}
public void onProviderEnabled(String s)
{
}}
location.getlatitude()获取网络供应商的纬度,萨姆斯无二经度
location.getlatitude() gets the latitude from the network provider, sames goes for longitude
这篇关于如何在谷歌地图获取当前位置使用地图视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!