如何显示像谷歌地图应用程序那样的方向标记

时间:2015-06-23 14:05:57

标签: android google-maps google-maps-api-3

我一直在搜索这个,但没有获得任何资源,我想在当前位置显示与Google Map应用程序类似的方向标记。看附件(带方向的蓝色标记)

它叫什么?

enter image description here

请帮助我,我创建了一个当前位置的地图。

活动代码

public class MainActivity extends FragmentActivity implements OnMapReadyCallback, LocationListener {

private GoogleMap map;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);

    map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
public void onMapReady(GoogleMap googleMap) {
    googleMap.setMyLocationEnabled(true);
}

@Override
public void onLocationChanged(Location location) {
    map.clear();
    MarkerOptions mp = new MarkerOptions();
    mp.position(new LatLng(location.getLatitude(), location.getLongitude()));
    mp.title("my position");
    mp.icon(BitmapDescriptorFactory
            .defaultMarker(BitmapDescriptorFactory.HUE_ROSE));
    map.addMarker(mp);
    map.animateCamera(CameraUpdateFactory.newLatLngZoom(
            new LatLng(location.getLatitude(), location.getLongitude()), 16));
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {

}

@Override
public void onProviderEnabled(String provider) {

}

@Override
public void onProviderDisabled(String provider) {

}
}

1 个答案:

答案 0 :(得分:0)

我认为你的onMapReady回调没有被解雇。使用getMapAsync这样的((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMapAsync(this)方法googleMap.setMyLocationEnabled(true)。然后应该调用/app/Resources/translations/messages.en.xliff方法,你就能看到你的方位。