11

我正在使用 Google Maps Android API V2。当我使用 Googlemap setMyLocationEnabled(true) 时,当前位置显示为一个蓝点。如何将当前位置显示为可以指示当前航向的闪烁箭头?

4

4 回答 4

6

移动!

如果设备是静止的,则该位置将在地图上用一个小蓝点指示,如果设备正在移动,则该位置将显示为一个 V 形。

来自谷歌地图 v2 文档

于 2013-09-27T07:43:29.670 回答
0

根据这篇文章,我们无法在默认情况下或通过 Android 上的 API 获得我们在 Google 的 Google 地图应用程序中看到的蓝色箭头。我的结论是,对于那个特定的功能,我们可能是靠我们自己的。只是我的2美分。

于 2014-05-02T02:47:47.120 回答
-1

在下面使用它可以获取当前位置

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);     
    Criteria criteria = new Criteria();
   String provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);

 if (location != null) {
                    System.out.println("Provider " + provider + " has been selected.");
                    onLocationChanged(location);
                  } 

Geocoder geocoder = new Geocoder(ViewTestDrive.this, Locale.getDefault());
                List<Address> addresses = null;

                try {
                    addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
                } catch (IOException e) {
                    e.printStackTrace();
                    // Update address field with the exception.
                    //Message.obtain(mHandler, UPDATE_ADDRESS, e.toString()).sendToTarget();
                }
                String addressText = null;
                if (addresses != null && addresses.size() > 0) {
                    Address address = addresses.get(0);
                    // Format the first line of address (if available), city, and country name.
                     addressText = String.format("%s, %s, %s",
                            address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
                            address.getLocality(),
                            address.getCountryName());
                    // Update address field on UI.
                    //Message.obtain(mHandler, UPDATE_ADDRESS, addressText).sendToTarget();
                }


                Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
                        Uri.parse("http://maps.google.com/maps?saddr="+addressText+"&daddr="+));
                intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");        
                startActivity(intent);


@Override
public void onLocationChanged(Location location) {
    int lat = (int) (location.getLatitude());
    int lng = (int) (location.getLongitude());
    String.valueOf(lat);
    String.valueOf(lng);

}


@Override
public void onProviderDisabled(String provider) {
    Toast.makeText(this, "Disabled provider " + provider,
            Toast.LENGTH_SHORT).show();

}


@Override
public void onProviderEnabled(String provider) {
    Toast.makeText(this, "Enabled new provider " + provider,
            Toast.LENGTH_SHORT).show();

}


@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    // TODO Auto-generated method stub

}
于 2013-01-02T09:39:50.757 回答
-1

(对不起,我来不及回答了。希望你在这个时候解决问题。)

您可以通过一些简单的步骤自定义标记的显示方式。以下是实现此目的所需的代码部分。

//You need a GoogleMap object to deal with the map functionality.
private GoogleMap map;
...
//Find Your Map view from layout
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
//This method will do the rest needed
showMarker(userLatitude, userLongitude)
...
...
// Pass the desired latitude and longitude to this method
public void showMarker(Double lat, Double lon) {
    map.clear();
    // Create a LatLng object with the given Latitude and Longitude
    LatLng markerLoc = new LatLng(lat, lon);

    //Add marker to map
    map.addMarker(new MarkerOptions()
            .position(markerLoc)                                                                        // at the location you needed
            .title("Desired Title")                                                                     // with a title you needed
            .snippet("Any summary if needed")                                                           // and also give some summary of available
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.your_flashing_arrow_anim_drawable))); // and give your animation drawable as icon
}

// To work these functionalities, you may require the following imports
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

最后布局应该包含一个像这样的条目,如 MAP

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />

希望这也能解决其他一些问题...... :)

于 2013-09-27T07:06:47.077 回答