【问题标题】:Google map start showing my current location from africa and then moves camera to my current location谷歌地图开始显示我在非洲的当前位置,然后将相机移动到我当前的位置
【发布时间】:2017-02-01 12:03:55
【问题描述】:

我知道以前有人问过这个问题,但是我没有得到解决方案。我的 android 应用程序开始显示我在非洲的位置,然后相机移向我当前的位置。任何人都可以帮助理解这种行为并为我提供一些解决方案来解决这个问题。

下面是我的部分代码

    //ON CONNECTION SUCCESSFUL USING GOOGLECLIENTAPI
@Override
public void onConnected(Bundle bundle) {
    checkPermission();
    Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
    if (location != null) {
        pointUserCurrentLocationOnMap(location);
        userLocation = location;

        saveLocationIfDoesNotExistInSqliteAndBackend();
    } else {
        checkSettingIsProper();
    }
}

     public void pointUserCurrentLocationOnMap(Location lastknownLocation) {

    mMap.clear();
    enableUserLocationButton(true);
    userLocation = lastknownLocation;

    currentLocation = new LatLng(lastknownLocation.getLatitude(), lastknownLocation.getLongitude());
    MarkerOptions markerOptions = new MarkerOptions().position(currentLocation).title("You");
    Marker marker = mMap.addMarker(markerOptions);
    marker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.ic_person_pin_circle_black_24dp));
    marker.showInfoWindow();

//bounds= latlngbound which is initialize when user search some thing
    if (bounds != null) {     
        mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, (int) JobSmithApplication.convertPixelsToDp(50f, this)));
    } else {
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLocation, 14f));
    }

    mMap.setOnMarkerClickListener(this);
    mMap.setOnMyLocationButtonClickListener(this);

}

我的代码有问题吗?

【问题讨论】:

    标签: android geolocation google-maps-android-api-2


    【解决方案1】:

    地图第一次加载时,会打开lat-long 0,0,也就是我们赤道的中心点,然后当触发“onChange”时,会加载新的lat-long位置并进行更新。所以相机移动到用户的当前位置。希望这会有所帮助。

    【讨论】:

    • 你能提供一些文档链接,以便我可以更深入地阅读它
    • 您提供的链接没有说明非洲的默认坐标 0.0。但是我找到了解决方案。我正在使用导致问题的 animateCamera() 。解决方案是使用 moveCamera() 正如他所说的 here
    • 你也可以试试这个页面吗sitepoint.com/…
    【解决方案2】:

    在 logcat 中检查您的 lastKnownLocation 的纬度和经度,看看您得到了什么

    【讨论】:

      【解决方案3】:

      在您的配置中或全局设置您的应用程序特定位置。当你初始化你的谷歌地图时,你的视图动画到你指定的位置。

      GoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(Configuration.DEFAULT_LAT, Configuration.DEFAULT_LONG), 14.0f));
      

      每当您打开应用时,上面的代码都会将应用的地图视图更改为您配置的位置,而当您的位置发生变化时,其余的工作都会发生。

      【讨论】:

        猜你喜欢
        • 2018-02-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-14
        • 2020-02-29
        • 2017-08-29
        相关资源
        最近更新 更多