【问题标题】:Android Google map customize my current location安卓谷歌地图自定义我当前位置
【发布时间】:2014-04-01 11:05:05
【问题描述】:

我已经实现了谷歌地图来查找位置和我当前的位置..位置和我当前的位置显示得很好。但是我当前的位置用蓝点表示(默认),我想自定义。我知道它会通过标记来完成,但是不工作... 这是我的代码..

private void initilizeMap() {
        if (googleMap == null) {
            googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                    R.id.map)).getMap();

            googleMap.getUiSettings().setCompassEnabled(false);
            googleMap.getUiSettings().setRotateGesturesEnabled(true);
            googleMap.setMyLocationEnabled(true);
            googleMap.getUiSettings().setMyLocationButtonEnabled(true);

            MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Target Location  + "+ latitude+"  +"+longitude);
            marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW));
         // adding marker
             googleMap.addMarker(marker);
             Location myLocation  = googleMap.getMyLocation();
             if(myLocation!=null)
             {
                 double dLatitude = myLocation.getLatitude();
                 double dLongitude = myLocation.getLongitude();
                 Log.i("APPLICATION"," : "+dLatitude);
                 Log.i("APPLICATION"," : "+dLongitude);
                 googleMap.addMarker(new MarkerOptions().position(
                         new LatLng(dLatitude, dLongitude)).title("My Location").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
                // mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(dLatitude, dLongitude), 8));*/

             }
             else
             {
                 Toast.makeText(this, "Unable to fetch the current location", Toast.LENGTH_SHORT);
             }
             }

【问题讨论】:

  • 你检查过你得到了纬度和经度的值吗?记录你的价值观。
  • 还将您的相机放置到您的位置......googleMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(myLocation .getLatitude(), myLocation.getLongitude())));

标签: android google-maps


【解决方案1】:

在初始化地图时设置新标记的位置。但是位置提供商会更新您的位置以找到您的真实位置。因此,您应该在每次更新时跟踪您的位置并更改标记位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-22
    • 1970-01-01
    • 1970-01-01
    • 2015-12-02
    相关资源
    最近更新 更多