对于 Pokemon Go,我认为标记实际上不在 GoogleMap 上。如果您想在地图中心修复图像(或任何类型的视图)...只需确保图像位于 xml 文件中地图的中心。
像这样:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@mipmap/ic_self_position"/>
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
所以现在您在地图中心有了一个标记。好的,但是您仍然没有将其与用户位置同步...所以让我们解决这个问题。
我假设您在开始地图时没有问题。所以,就这样吧,我等着。完毕?行。地图集。
别忘了禁用地图中的拖动功能:
@Override
public void onMapReady(GoogleMap googleMap) {
googleMap.getUiSettings().setScrollGesturesEnabled(false);
...
}
让我们接收用户位置并移动地图。
使用此链接:
https://developer.android.com/training/location/receive-location-updates.html
但是将代码的某些部分更改为:
public class MainActivity extends ActionBarActivity implements
ConnectionCallbacks, OnConnectionFailedListener, LocationListener {
...
@Override
public void onLocationChanged(Location location) {
mCurrentLocation = location;
mLastUpdateTime = DateFormat.getTimeInstance().format(new Date());
moveUser(Location location);
}
private void moveUser(Location location) {
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
mGoogleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
mCharacterImageView.animate(pretendThatYouAreMovingAnimation)
[you can make a animation in the image of the user... like turn left/right of make walk movements]
}
}
如果你想在移动方向上旋转你的角色,你需要将之前的 Latlng 与新的 Latlng 进行比较,然后旋转你的图像(或视图......或任何东西)以指向移动方向。
如果您需要更多信息,也许这个 repo 可以帮助您:CurrentCenterPositionMap
(repo 不会做你想做的事......它只使用了我解释的相同概念。)