你不能处理点击谷歌地图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