你不能處理點擊谷歌地圖MyLocation按鈕的情況下,是的,但有一個小竅門,通過它,你可以得到的行爲根據自己的需要:
先在你layout.xml文件中添加地圖和假MyLocation按鈕。
你可以用相對佈局的幫助下實現這一目標:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/myLocationButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/mylocation" />
</RelativeLayout>
你可以採取「mylocation.png」似乎像你在谷歌地圖上看到的。
LocationManager locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String s = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(s);
您的虛擬MyLocation按鈕呼叫點擊事件,在其中您將添加標記
private GoogleMap googleMap; googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude()); googleMap.addMarker(new MarkerOptions().icon(YOUR_MODIFIED_ICON).position(latLng).title(TITLE).snippet(SNIPET));
這樣可以修改谷歌地圖的默認圖標。
是啊,你也需要設置縮放級別:
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
你檢查你的SDK中的谷歌地圖V2已經以實例闡述與您的自定義圖像添加標記的功能和旋轉的演示它也相應地。 – GrIsHu 2013-02-16 04:45:00
嘿Grishu,我確實看了一下SDK中的例子,演示程序的哪個部分專門看着旋轉我的位置圖標?我似乎無法找到它。 – Gyroscope 2013-02-23 03:13:39
在sdk demo中,檢查已經顯示在地圖上添加標記的方式的標記類。 – GrIsHu 2013-02-23 04:40:43