我使用ImageView在地图上放置一个标记,以便在地图移动时它不会移动。如何在打开时将ImageView放在地图(赤道)的中心。如何获取ImageView在地图上的位置的纬度和经度。我在谷歌搜索但没有得到代码。请帮助我....
activity_main.xml中:
<?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>
MainActivity.java:
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);
}}
答案 0 :(得分:2)
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);
}
}
答案 1 :(得分:1)
您可以将自己的标记添加到googleMap
@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);
}}