如何在Android谷歌地图中显示当前位置?
我想在谷歌地图中显示设备的当前位置我该怎么做我现在正在显示普通地图。以下代码显示设备的Lat和LAG位置我该如何使用Lat和LAG位置在地图中显示地址如何在Android谷歌地图中显示当前位置?,android,google-maps,currentlocation,Android,Google Maps,Currentlocation,我想在谷歌地图中显示设备的当前位置我该怎么做我现在正在显示普通地图。以下代码显示设备的Lat和LAG位置我该如何使用Lat和LAG位置在地图中显示地址 package com.appulento.mapsexample.pack; import android.content.Context; import android.content.Intent; import android.location.Location; import android.location.LocationListe
package com.appulento.mapsexample.pack;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Toast;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class MapsMianClass extends MapActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mapview1);
mapView.setBuiltInZoomControls(true);
/* Use the LocationManager class to obtain GPS locations */
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
}
/* Class My Location Listener */
public class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc)
{
loc.getLatitude();
loc.getLongitude();
String Text = "My current location is: " +
"Latitud = " + loc.getLatitude() +
"Longitud = " + loc.getLongitude();
Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderDisabled(String provider)
{
Toast.makeText( getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT ).show();
}
@Override
public void onProviderEnabled(String provider)
{
Toast.makeText( getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
提前谢谢
请告诉我哪个步骤会导致问题。由于这个问题已经存在一年多了,在Android上显示地图的方法已经改变了 获得当前位置(纬度和经度)后,只需将此坐标传递给地图标记 以下是我从文档中复制粘贴的片段:
private GoogleMap mMap;
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Hello world"));
至于如何使用谷歌地图,他们在文档中也有完整的指南
我在这里粘贴了完整步骤的链接,为您节省了一条腿:
如果您仔细地按照此处的步骤操作,则应该显示地图并显示标记,而不会出现任何问题
这里还有一件事您可能需要注意:在API控制台中启用Google Maps选项时,请确保您正在启用Google Maps Android API V2,并确保在检索API密钥时选择了正确的证书
希望这能帮助您摆脱迷雾。使用反向地理编码将这些latlngs转换为地址,然后您可以使用文本视图或Toast来显示该地址。 这个链接可能会有帮助。
你为什么不看看这页的右下角..然后点击相关中给出的链接我在将地图移动到当前位置时遇到了问题我正在获取lat和lang位置。刚才我编辑了我的最新代码