2013-04-07 66 views
0

这里是我的代码:如何添加标题和片段,以谷歌的MyLocation引脚(谷歌地图的Android API第2版)

// Declare map 
private GoogleMap map; 
... 
// Initialise map 
map = ((MapFragment) findFragmentById(R.id.map)).getMap(); 
... 
// Set location 
map.setMyLocation(true); 

在被按压时谷歌的MyLocation针,我希望有一个标题和摘要的出现。与正常的标记,这可以通过以下方式实现:

Marker marker = map.addMarker(new MarkerOptions().position(position) 
.title("My Location") 
.snippet("You are here!") 
.icon(BitmapDescriptorFactory.fromResource(R.drawable.pin))); 

凡.title伪(“”)设置一个标题和是.snippet(“”)设置一个代码段;但我不确定如何使用Google的MyLocation引脚进行此操作。

有人可以请解释如何做到这一点。

回答

0

这正是我想知道的。 我试图使用的代码上myLocation图标添加标记:

Marker marker = map.addMarker(new MarkerOptions().position(latLng) 
.title("You are here")); 

的latLng从纬度和经度获取数据双打

double latitude = myLocation.getLatitude(); 
double longitude = myLocation.getLongitude();  
LatLng latLng = new LatLng(latitude, longitude); 

这增加了一个标记到屏幕但它是出路与MyLocation标记同步。我认为这与位置有关。它是从网络或无线而不是GPS获取位置。

这一直在我的头几天,我想知道为什么。