我认为 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 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 进行比较,并旋转您的图像(或视图...或任何内容)以指向移动方向。
如果您需要更多信息,也许这个存储库可以帮助您:当前中心位置图 https://github.com/leandroBorgesFerreira/CurrentCenterPositionMap
(回购协议不做你想做的事......它只使用与我的解释相同的概念。)