Jellybean中的“Google Maps”应用程序有一个指标,可根据您所面对的方式进行调整。我有兴趣实施类似的指标,但有多个指标。
有没有人知道他们如何实现他们的标题指示器(请注意,即使旋转地图,它也会保持其标题)。我尝试使用标记自己的方法,然后我意识到标记不会随着地图一起旋转(在几个小时的劳动之后的那种时刻......)
总结:如何在谷歌地图中实施基于标题而非地图旋转的图标。
现在我看到两个解决方案:
在我开始另一个兔子洞之前,有人可以提供任何建议吗?谢谢!
答案 0 :(得分:2)
如果您想在地图上显示方向,可以执行几项操作。
以下是所有使用的导入:
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
1.移动地图,使轴承位于顶部。
private final GoogleMap mMap;
//Get the current position from the map
CameraPosition camPosition = mMap.getCameraPosition();
//Update only the orientation/bearing, get all of the other values from the existing position.
CameraPosition newPos = new CameraPosition(
camPosition.target,
camPosition.zoom,
camPosition.tilt,
azimuthInDegress);
//Set the position so that the map will update. The desired heading should not be on top
mMap.moveCamera(CameraUpdateFactory.newCameraPosition(newPos));
这个想法的问题是,如果你没有稳定你的方向更新,地图将移动到处。
2.实现LocationSource
Google地图可让您覆盖其位置提供商。首先,您需要实现一个新的位置源:
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.LocationSource;
import com.google.android.gms.maps.MapFragment;
public class LocationSourceImplActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Assume using the example from Google
GoogleMap map = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.map)).getMap();
map.setMyLocationEnabled(true);
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
map.setLocationSource(new LocationSourceImpl(locManager));
}
/**
*The Goal of this class is to listen for both location and heading updates
*and combine these into a single update, which will be passed to Google Maps.
*/
private class LocationSourceImpl implements LocationSource, LocationListener {
private OnLocationChangedListener mListener = null;
private Location mLastLoc = null;
//Use your desired location provider. You can also update this class to better
//determine when and how to register
private static final String PREF_LOC_SRC ="";
private final LocationManager mLocationManager;
private float mLastHeading = Float.MAX_VALUE;
public LocationSourceImpl(LocationManager pLocManager) {
mLocationManager = pLocManager;
//Get all updates, modify as desired.
mLocationManager.requestLocationUpdates(PREF_LOC_SRC, 0, 0, this);
}
@Override
public void onLocationChanged(Location location) {
mLastLoc = location;
notifyListener();
}
private void notifyListener() {
if(mListener != null && mLastLoc!=null) {
if(mLastHeading != Float.MAX_VALUE) {
mLastLoc.setBearing(mLastHeading);
}
//The listener will be the maps:
mListener.onLocationChanged(mLastLoc);
}
}
@Override
public void activate(OnLocationChangedListener pListener) {
//When the setLocationSource is called on the map, the map
//will be passed in as an OnLocationChangedListener (may not be the
//map, but may be a delegator created by the map.
mListener = pListener;
}
@Override
public void deactivate() {
mListener = null;
}
/**
* This method can/should be replaced with a heading calculation
* @param pDegrees
* Heading in degrees
*/
public void updateHeadingInDegrees(float pDegrees) {
mLastHeading = pDegrees;
notifyListener();
}
@Override
public void onProviderDisabled(String paramString) {
}
@Override
public void onProviderEnabled(String paramString) {
}
@Override
public void onStatusChanged(String paramString, int paramInt,
Bundle paramBundle) {
}
}
}
答案 1 :(得分:0)
这是使用指南针根据磁场获得您所面对的方向。在这里看到有关不同传感器的信息
http://developer.android.com/guide/topics/sensors/sensors_overview.html
答案 2 :(得分:0)
使用它。这是使用设备自己的传感器实现的。
正如你想了解的观点,我认为这是一个对你有帮助的例子http://android-er.blogspot.in/2010/08/simple-compass-sensormanager-and.html