作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在 google map
上查看位置 我的应用程序获取了该位置的纬度和经度,但该位置未显示在 google map 中。我使用 firebase 数据库存储 latitude 和 longitude
这是 map Activity 的代码
public class MapsActivity extends FragmentActivity implements GoogleMap.OnMyLocationButtonClickListener, GoogleMap.OnMyLocationClickListener, OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap map) {
mMap = map;
// TODO: Before enabling the My Location layer, you must request
// location permission from the user. This sample does not include
// a request for location permission.
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
mMap.setMyLocationEnabled(true);
mMap.setOnMyLocationButtonClickListener(this);
mMap.setOnMyLocationClickListener(this);
}
@Override
public void onMyLocationClick(@NonNull Location location) {
Toast.makeText(this, "Current location:\n" + location, Toast.LENGTH_LONG).show();
}
@Override
public boolean onMyLocationButtonClick() {
Toast.makeText(this, "MyLocation button clicked", Toast.LENGTH_SHORT).show();
// Return false so that we don't consume the event and the default behavior still occurs
// (the camera animates to the user's current position).
return false;
}
}
最佳答案
使用此方法并将 4 个参数传递给此给定方法。首先它会导航到一个特定的地方并添加那个地方的标记。
示例:
public static Marker addPinPoint(GoogleMap map, Marker locationMarker, double selectLatitude, double selectLongitude){
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(locationLatitude, locationLongitude), fZoom));
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
Bitmap iconImage = ResourceUtil.getBitmap(App.getInstance().getContext(), R.drawable.icon_location_center); // your location icon
BitmapDescriptor icon = BitmapDescriptorFactory.fromBitmap(iconImage);
locationMarker = map.addMarker(new MarkerOptions()
.anchor(0.0f, 1.0f)
.icon(icon)
.position(new LatLng(selectLatitude, selectLongitude)));
return locationMarker;
}
关于android - 在发送纬度和经度的谷歌地图上查看位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54643171/
leaflet:一个开源并且对移动端友好的交互式地图 JavaScript 库 中文文档: https://leafletjs.cn/reference.html 官网(英文): ht
我是一名优秀的程序员,十分优秀!