如何在Google Maps Android API V2中将当前位置显示为箭头?

11

我正在使用Google Maps Android API V2。当我使用Googlemap setMyLocationEnabled(true)时,当前位置会显示为蓝点。如何将当前位置显示为闪烁的箭头,以指示当前方向?

3个回答

6

移动!

如果设备处于静止状态,则在地图上的小蓝点表示位置,如果设备正在移动,则表示为矢车菱形。

来源:Google 地图 v2 文档


简短而精炼的回答..!! - Vishavjeet Singh

0
无法通过Android API默认获取类似谷歌地图应用中看到的蓝色箭头,根据this post的说法。我得出结论,我们可能需要自己实现该特定功能。这只是我的个人意见。

-1

(抱歉,我回答晚了。希望你现在已经解决了问题。)

您可以通过简单的步骤自定义标记的显示方式。以下是实现此目的所需的代码部分。

//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" />

希望这也能解决其他人的问题... :)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接