android imageview';s在地图上的位置
我使用ImageView在地图顶部放置了一个标记,这样当地图移动时它就不会移动。打开时如何将ImageView放置在地图的中心(赤道)。如何获取ImageView在地图上位置的纬度和经度。我在谷歌上搜索,但没有得到代码。请帮助我 activity_main.xml:android imageview';s在地图上的位置,android,google-maps,Android,Google Maps,我使用ImageView在地图顶部放置了一个标记,这样当地图移动时它就不会移动。打开时如何将ImageView放置在地图的中心(赤道)。如何获取ImageView在地图上位置的纬度和经度。我在谷歌上搜索,但没有得到代码。请帮助我 activity_main.xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/an
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.jobinsabu.markeranimator.MainActivity">
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map1"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"> </fragment>
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="Map Animator"
android:id="@+id/map_label"
android:background="#70ffffff"
android:textColor="#000000"
android:textSize="25sp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:visibility="visible"
android:src="@drawable/marker"
android:id="@+id/imageView"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
您可以将自己的标记添加到谷歌地图
@Override
public void onMapReady(final GoogleMap googleMap) {
googlemap=googleMap;
googlemap.getUiSettings().setCompassEnabled(true);
googlemap.getUiSettings().setAllGesturesEnabled(true);
googlemap.getUiSettings().setZoomControlsEnabled(true);
googleMap.getUiSettings().setZoomGesturesEnabled(true);
Marker myMarker = map.addMarker(new MarkerOptions()
.position(yourLocation)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
googleMap.addMarker(myMarker);
}}
但是,当用户移动地图时,标记应始终对用户可见。地图移动时,标记对应于特定的lat、lng位置。因此,标记不总是可见的。直到您返回到上一个位置时,标记才可见我尝试过使用标记,但我希望在更改地图的相机位置时标记不可移动。就像UberYes一样,我的答案是相同的,标记将不可移动。当我使用ImageView而不是标记时,效果很好,但是如何把它放在中心你说的中心是什么意思?用户的当前位置还是什么?如果有效,这可能有助于选择答案。。。!!
@Override
public void onMapReady(final GoogleMap googleMap) {
googlemap=googleMap;
googlemap.getUiSettings().setCompassEnabled(true);
googlemap.getUiSettings().setAllGesturesEnabled(true);
googlemap.getUiSettings().setZoomControlsEnabled(true);
googleMap.getUiSettings().setZoomGesturesEnabled(true);
Marker myMarker = map.addMarker(new MarkerOptions()
.position(yourLocation)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
googleMap.addMarker(myMarker);
}}
public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {
ImageView marker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
marker=(ImageView) findViewById(R.id.marker);
SupportMapFragment supportMapFragment=(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map1);
supportMapFragment.getMapAsync(this);}
@Override
public void onMapReady(final GoogleMap googleMap) {
googlemap=googleMap;
googlemap.getUiSettings().setCompassEnabled(true);
googlemap.getUiSettings().setAllGesturesEnabled(true);
googlemap.getUiSettings().setZoomControlsEnabled(true);
googleMap.getUiSettings().setZoomGesturesEnabled(true);
Marker marker = googleMap.addMarker(new MarkerOptions()
.position(lat_lng_of_equator)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ImageView_of_marker)));
googleMap.addMarker(marker);
}
}