如何在谷歌地图Android API V2?中以箭头形式显示当前位置;
我正在使用谷歌地图Android API V2。当我使用Googlemap setMyLocationEnabled(true)时,当前位置显示为一个蓝点。如何将当前位置显示为可以指示当前标题的闪烁箭头 在其工作的下方使用以获取当前位置如何在谷歌地图Android API V2?中以箭头形式显示当前位置;,android,google-maps,google-maps-api-2,Android,Google Maps,Google Maps Api 2,我正在使用谷歌地图Android API V2。当我使用Googlemap setMyLocationEnabled(true)时,当前位置显示为一个蓝点。如何将当前位置显示为可以指示当前标题的闪烁箭头 在其工作的下方使用以获取当前位置 LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Cr
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
if (location != null) {
System.out.println("Provider " + provider + " has been selected.");
onLocationChanged(location);
}
Geocoder geocoder = new Geocoder(ViewTestDrive.this, Locale.getDefault());
List<Address> addresses = null;
try {
addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
} catch (IOException e) {
e.printStackTrace();
// Update address field with the exception.
//Message.obtain(mHandler, UPDATE_ADDRESS, e.toString()).sendToTarget();
}
String addressText = null;
if (addresses != null && addresses.size() > 0) {
Address address = addresses.get(0);
// Format the first line of address (if available), city, and country name.
addressText = String.format("%s, %s, %s",
address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
address.getLocality(),
address.getCountryName());
// Update address field on UI.
//Message.obtain(mHandler, UPDATE_ADDRESS, addressText).sendToTarget();
}
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+addressText+"&daddr="+));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
@Override
public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude());
int lng = (int) (location.getLongitude());
String.valueOf(lat);
String.valueOf(lng);
}
@Override
public void onProviderDisabled(String provider) {
Toast.makeText(this, "Disabled provider " + provider,
Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderEnabled(String provider) {
Toast.makeText(this, "Enabled new provider " + provider,
Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
LocationManager LocationManager=(LocationManager)getSystemService(Context.LOCATION\u服务);
标准=新标准();
字符串提供程序=locationManager.getBestProvider(条件,false);
Location Location=locationManager.getLastKnownLocation(提供者);
如果(位置!=null){
System.out.println(“已选择提供程序”+提供程序+”);
onLocationChanged(位置);
}
Geocoder Geocoder=新的Geocoder(ViewTestDrive.this,Locale.getDefault());
列表地址=空;
试一试{
addresses=geocoder.getFromLocation(location.getLatitude(),location.getLatitude(),1);
}捕获(IOE异常){
e、 printStackTrace();
//使用异常更新地址字段。
//Message.get(mHandler,UPDATE_ADDRESS,例如toString()).sendToTarget();
}
字符串addressText=null;
if(addresses!=null&&addresses.size()>0){
地址=地址。获取(0);
//格式化地址(如果可用)、城市和国家名称的第一行。
addressText=String.format(“%s,%s,%s”,
address.getMaxAddressLineIndex()>0?address.getAddressLine(0):“”,
address.getLocation(),
address.getCountryName());
//在UI上更新地址字段。
//获取(mHandler,UPDATE_ADDRESS,addressText).sendToTarget();
}
意向意向=新意向(android.content.Intent.ACTION\u视图,
解析http://maps.google.com/maps?saddr=“+addressText+”&daddr=“+);
intent.setClassName(“com.google.android.apps.maps”,“com.google.android.maps.MapsActivity”);
星触觉(意向);
@凌驾
已更改位置上的公共无效(位置){
intlat=(int)(location.getLatitude());
int lng=(int)(location.getLongitude());
字符串.valueOf(lat);
字符串的值(液化天然气);
}
@凌驾
公共无效onProviderDisabled(字符串提供程序){
Toast.makeText(此“禁用的提供程序”+提供程序,
吐司。长度(短)。show();
}
@凌驾
公共无效onProviderEnabled(字符串提供程序){
Toast.makeText(此“已启用的新提供程序”+提供程序,
吐司。长度(短)。show();
}
@凌驾
public void onStatusChanged(字符串提供程序、int状态、Bundle extra){
//TODO自动生成的方法存根
}
(对不起,我来不及回答。希望您在这个时候解决了这个问题。)
您可以通过一些简单的步骤自定义标记的显示方式。
以下是实现这一点所需的代码部分
//You need a GoogleMap object to deal with the map functionality.
private GoogleMap map;
...
//Find Your Map view from layout
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
//This method will do the rest needed
showMarker(userLatitude, userLongitude)
...
...
// Pass the desired latitude and longitude to this method
public void showMarker(Double lat, Double lon) {
map.clear();
// Create a LatLng object with the given Latitude and Longitude
LatLng markerLoc = new LatLng(lat, lon);
//Add marker to map
map.addMarker(new MarkerOptions()
.position(markerLoc) // at the location you needed
.title("Desired Title") // with a title you needed
.snippet("Any summary if needed") // and also give some summary of available
.icon(BitmapDescriptorFactory.fromResource(R.drawable.your_flashing_arrow_anim_drawable))); // and give your animation drawable as icon
}
// To work these functionalities, you may require the following imports
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
最后,布局应该包含这样一个条目作为MAP
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
希望这也能解决其他一些问题……:) 行动
如果设备处于静止状态,则地图上会显示一个蓝色小点,如果设备处于移动状态,则地图上会显示一个V形小点
从可以看出,默认情况下或通过Android上的API获得谷歌地图应用程序中的蓝色箭头是不可能的。我的结论是,我们可能需要依靠自己的力量来实现这一特定功能。只有我的2美分。这只回答了一半的问题。我更感兴趣的是如何在地图顶部绘制箭头,设置它的动画(即,不是标记),并保持它与用户位置同步,即使在地图滚动时也是如此。我认为这根本不能回答问题。这个问题的重点是实现蓝色箭头,就像谷歌官方地图应用程序中的箭头一样。答案简短而甜美。。!!