2
A
回答
2
我沒有找到任何風格cusomization。標記不能被替換。
我做了一個自定義圖塊和一個自定義getCurrentLocation函數。
這裏是我的代碼:
首先,你需要在右上角找到我按鈕瓷磚。我將它添加到佈局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="android.support.v4.app.FragmentActivity" >
<fragment
android:id="@+id/tabs_fragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.bucons.savetime.MyMapFragment" />
<ImageButton
android:id="@+id/myLocationButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="4dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_menu_mylocation"
android:background="@drawable/map_tile_bg" />
</RelativeLayout>
所需要的資源是@繪製/ ic_menu_mylocation 你可以得到它:https://docs.google.com/file/d/0BzGos46YSzYfWkRYS2ZMNmdZREk/edit
而對於背景:@繪製/ map_tile_bg:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_shortAnimTime">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<stroke
android:width="1px"
android:color="@color/map_tile_bg_stroke_pressed"/>
<solid android:color="@color/map_tile_bg_solid_pressed"/>
<corners android:radius="1dp"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<stroke
android:width="1px"
android:color="@color/map_tile_bg_stroke"/>
<solid android:color="@color/map_tile_bg_solid"/>
<corners android:radius="1dp"/>
</shape>
</item>
</selector>
顏色轉換器有:
<color name="map_tile_bg_solid">#aaffffff</color>
<color name="map_tile_bg_stroke">#ffcccccc</color>
<color name="map_tile_bg_solid_pressed">#aaFF9933</color>
<color name="map_tile_bg_stroke_pressed">#ffcccccc</color>
這裏是我的片段:
public class MyMapFragment extends SupportMapFragment {
//Current location Marker
private Marker myLocationMarker;
GoogleMap map = null;
public MyMapFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setUpMapIfNeeded();
getCurrentLocation();
}
//set the map and set the tile for locate me button
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (map == null) {
map = getMap();
// Check if we were successful in obtaining the map.
if (map != null) {
//Top right button for go to location
ImageButton locateMeTile = (ImageButton) getSherlockActivity().findViewById(R.id.myLocationButton);
locateMeTile.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
getCurrentLocation();
}
});
}
}
}
//retrieve the current position. Only once
private void getCurrentLocation() {
locationManager = (LocationManager) getSherlockActivity().getSystemService(Context.LOCATION_SERVICE);
Criteria crit = new Criteria();
String towers = locationManager.getBestProvider(crit, false);
Location location = locationManager.getLastKnownLocation(towers);
Double glat = null;
Double glon = null;
if(location != null){
glat = location.getLatitude();
glon = location.getLongitude();
}
CameraPosition pos = new CameraPosition.Builder()
.target(new LatLng(glat, glon))
.zoom(10)
.build();
if(pos != null) {
currLocationChange(pos.target);
map.animateCamera(CameraUpdateFactory.newCameraPosition(pos));
} else {
Toast.makeText(getSherlockActivity(), R.string.main_error, Toast.LENGTH_LONG).show();
}
}
//Add pin to the current Location or move existing
private void currLocationChange(LatLng loc) {
if(myLocationMarker != null) {
myLocationMarker.setPosition(new LatLng(loc.latitude,loc.longitude));
} else {
myLocationMarker = map.addMarker(new MarkerOptions()
.position(new LatLng(loc.latitude,loc.longitude)));
}
}
}
相關問題
- 1. Google地圖V2禁用MyLocation藍色圖標
- 2. Google地圖KML圖層樣式問題
- 3. 樣式KML圖層
- 4. 不設計圖層樣式
- 5. 合成圖層樣式
- 6. 谷歌地圖myLocation按鈕顏色 - IOS
- 7. 無法獲得「mylocation」谷歌地圖Android
- 8. Openlayers投影與OSM樣式的地圖和GeoJSON矢量圖層
- 9. Google地圖v2熱圖地圖人口
- 10. Android MapBox更改MyLocation標記的樣式
- 11. 在Google地圖v2中添加自定義圖層
- 12. 在G地圖中使用動畫GIF作爲地面疊加層地圖v2
- 13. Android地圖V2無法加載地圖
- 14. 谷歌地圖V2內或在地圖
- 15. 地圖不適用於地圖v2
- 16. 檢查谷歌地圖Android V2 didLoad/isCached地圖(離線模式)
- 17. 更改樣式Google地圖的樣式
- 18. 多樣式谷歌地圖
- 19. 谷歌地圖樣式uipopovercontroller
- 20. Photoshop圖層樣式到CoreGraphics代碼
- 21. 如何更改柵格圖層樣式
- 22. Leaflet獲取圖層的當前樣式
- 23. 設置多層融合表的樣式谷歌地圖
- 24. 谷歌地圖API v2。 android
- 25. Google地圖v2或v3?
- 26. Android Studio Google地圖v2
- 27. 谷歌地圖V2鍵
- 28. Android地圖V2崩潰
- 29. Android谷歌地圖API v2
- 30. 谷歌地圖Android版V2
太棒了!感謝您的解決方案,工作perfrect – OFFmind 2013-08-27 09:35:28