我想在谷歌地图上显示设备的当前位置,我该怎么做呢?我正在显示正常地图,现在.the跟随代码,显示设备的纬度和语言位置,如何使用Lat和Lang位置在地图中显示地址。
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;
}
}提前感谢……
发布于 2013-07-29 07:25:25
由于这个问题已经存在一年多了,在Android上显示地图的方法已经改变了。
获得当前位置(经纬度)后,您需要做的就是将此坐标传递给地图标记。
下面是我从Google Maps Android API V2文档中复制和粘贴的代码片段:
private GoogleMap mMap;
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Hello world"));至于如何使用谷歌地图,他们在文档中也有一个完整的指南。
我在这里粘贴了完整步骤的链接,为您节省了一条腿:
Google Maps Android API V2 - Getting Started
如果您仔细按照步骤操作,您应该可以毫无问题地显示地图和标记。
这里还有一件事你可能需要注意:当在应用程序接口控制台中启用谷歌地图选项时,请确保您正在启用Google Maps Android API V2,并且还请确保您在检索API密钥时选择了正确的证书。
希望这能帮助你走出迷雾。
发布于 2012-04-27 17:09:54
请告诉我哪一步会出问题。
发布于 2015-10-07 14:48:30
使用反向地理编码将这些latlng转换为地址,然后您可以使用文本视图或Toast来显示该地址。此链接可能会有所帮助。http://www.oodlestechnologies.com/blogs/Displaying-Current-Location-on-Google-Maps
https://stackoverflow.com/questions/10347596
复制相似问题