我正在使用Google Maps Android API V2。当我使用Googlemap setMyLocationEnabled(true)时,当前位置会显示为蓝点。如何将当前位置显示为闪烁的箭头,以指示当前方向?
我正在使用Google Maps Android API V2。当我使用Googlemap setMyLocationEnabled(true)时,当前位置会显示为蓝点。如何将当前位置显示为闪烁的箭头,以指示当前方向?
(抱歉,我回答晚了。希望你现在已经解决了问题。)
您可以通过简单的步骤自定义标记的显示方式。以下是实现此目的所需的代码部分。
//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" />
希望这也能解决其他人的问题... :)