【问题标题】:Set marker to the center of circle (current location)将标记设置为圆心(当前位置)
【发布时间】:2015-04-16 16:25:17
【问题描述】:

我在我的应用程序中使用 Google Map Android API v2,我遇到了如下图所示的小问题,但不知道如何解决它。我将标记设置为设备的当前位置,但它现在位于圆心。我想将标记设置为圆心。有没有可能?

感谢您的帮助!

我使用的代码

// Showing status
if(status!= ConnectionResult.SUCCESS){ // Google Play Services are not available

    int requestCode = 10;
    Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
    dialog.show();

}else { // Google Play Services are available

    // Getting reference to the SupportMapFragment of activity_location.xml
    SupportMapFragment mSupportMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

    // Getting GoogleMap object from the fragment
    mGoogleMap = mSupportMapFragment.getMap();

    // Enabling MyLocation Layer of Google Map
    mGoogleMap.setMyLocationEnabled(true);

    // Getting LocationManager object from System Service LOCATION_SERVICE
    LocationManager mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    // Creating a criteria object to retrieve provider
    Criteria criteria = new Criteria();

    // Getting the name of the best provider
    String provider = mLocationManager.getBestProvider(criteria, true);

    // Getting Current Location
    Location location = mLocationManager.getLastKnownLocation(provider);

    if(location!=null){
        onLocationChanged(location);
    }
    mLocationManager.requestLocationUpdates(provider, 20000, 0, this);

    // Getting latitude of the current location
    double latitude = location.getLatitude();

    // Getting longitude of the current location
    double longitude = location.getLongitude();

    // Creating a LatLng object for the current location
    LatLng mLatLng = new LatLng(latitude, longitude);

    //Add Marker to current location of devise
    mGoogleMap.addMarker(new MarkerOptions()
            .position(mLatLng)
            .title("Geolocation system")
            .snippet("Your last current location which was available!"));
    //      .icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_location)));

    // Showing the current location in Google Map
    mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(mLatLng));

    // Show Zoom buttons
    mGoogleMap.getUiSettings().setZoomControlsEnabled(true);

    // Turns on 3D buildings
    mGoogleMap.setBuildingsEnabled(true);

    // Zoom in the Google Map
    mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(14));

【问题讨论】:

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


    【解决方案1】:

    您正在使用 GPS 和网络获取您的位置。这些没有提供您正确的位置,而您正在使用:-

    mGoogleMap.setMyLocationEnabled(true);

    这使用谷歌地图 api 显示您的位置。所以你和谷歌的位置不同。所以圆圈和标记显示不同的位置。

    因此您可以为此使用 google 的 Fuesed Location 客户端

    访问这里以获得更多帮助。 https://developer.android.com/reference/com/google/android/gms/location/FusedLocationProviderApi.html

    【讨论】:

      猜你喜欢
      • 2014-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多