如何实现超级地图之类的可拖动地图? 我正在使用Google Maps v2.实际上,我得到的解决方案是引用 这篇文章并在此处分享我的完整解决方案
最新回答
- 2021-1-101 #
- 2021-1-102 #
以
LocationClient
很遗憾,我用过GoogleApiClient
,这是任何想要实现它的人的代码。 只需更换LocationClient
与GoogleApiClient
其他与@Sishin的代码相同.import java.io.IOException; import java.util.List; import java.util.Locale; import android.app.Dialog; import android.content.IntentSender.SendIntentException; import android.location.Address; import android.location.Geocoder; import android.location.Location; import android.os.AsyncTask; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.LinearLayout; import android.widget.TextView; import com.app.anycabs.R; import com.app.common.GPSTracker; import com.app.modle.GData; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.PendingResult; import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.common.api.Status; import com.google.android.gms.location.LocationListener; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap.OnCameraChangeListener; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; public class MainActivity extends AppCompatActivity implements LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { // A request to connect to Location Services private LocationRequest mLocationRequest; GoogleMap mGoogleMap; public static String ShopLat; public static String ShopPlaceId; public static String ShopLong; // Stores the current instantiation of the location client in this object private GoogleApiClient mGoogleApiClient; boolean mUpdatesRequested = false; private TextView markerText; private LatLng center; private LinearLayout markerLayout; private Geocoder geocoder; private List<Address> addresses; private TextView Address; double latitude; double longitude; private GPSTracker gps; private LatLng curentpoint; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_curent_locations); markerText = (TextView) findViewById(R.id.locationMarkertext); Address = (TextView) findViewById(R.id.adressText); markerLayout = (LinearLayout) findViewById(R.id.locationMarker); // Getting Google Play availability status int status = GooglePlayServicesUtil .isGooglePlayServicesAvailable(getBaseContext()); if (status != ConnectionResult.SUCCESS) { // Google Play Services are // not available int requestCode = 10; Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode); dialog.show(); } else { // Google Play Services are available // Getting reference to the SupportMapFragment // Create a new global location parameters object mLocationRequest = LocationRequest.create(); /* * Set the update interval */ mLocationRequest.setInterval(GData.UPDATE_INTERVAL_IN_MILLISECONDS); // Use high accuracy mLocationRequest .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); // Set the interval ceiling to one minute mLocationRequest .setFastestInterval(GData.FAST_INTERVAL_CEILING_IN_MILLISECONDS); // Note that location updates are off until the user turns them on mUpdatesRequested = false; /* * Create a new location client, using the enclosing class to handle * callbacks. */ mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).build(); mGoogleApiClient.connect(); } } private void stupMap() { try { mGoogleMap = ((MapFragment) getFragmentManager().findFragmentById( R.id.curentlocationmapfragment)).getMap(); // Enabling MyLocation in Google Map mGoogleMap.setMyLocationEnabled(true); mGoogleMap.getUiSettings().setZoomControlsEnabled(false); mGoogleMap.getUiSettings().setMyLocationButtonEnabled(true); mGoogleMap.getUiSettings().setCompassEnabled(true); mGoogleMap.getUiSettings().setRotateGesturesEnabled(true); mGoogleMap.getUiSettings().setZoomGesturesEnabled(true); PendingResult<Status> result = LocationServices.FusedLocationApi .requestLocationUpdates(mGoogleApiClient, mLocationRequest, new LocationListener() { @Override public void onLocationChanged(Location location) { markerText.setText("Location received: " + location.toString()); } }); Log.e("Reached", "here"); result.setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status status) { if (status.isSuccess()) { Log.e("Result", "success"); } else if (status.hasResolution()) { // Google provides a way to fix the issue try { status.startResolutionForResult(MainActivity.this, 100); } catch (SendIntentException e) { e.printStackTrace(); } } } }); gps = new GPSTracker(this); gps.canGetLocation(); latitude = gps.getLatitude(); longitude = gps.getLongitude(); curentpoint = new LatLng(latitude, longitude); CameraPosition cameraPosition = new CameraPosition.Builder() .target(curentpoint).zoom(19f).tilt(70).build(); mGoogleMap.setMyLocationEnabled(true); mGoogleMap.animateCamera(CameraUpdateFactory .newCameraPosition(cameraPosition)); // Clears all the existing markers mGoogleMap.clear(); mGoogleMap.setOnCameraChangeListener(new OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition arg0) { // TODO Auto-generated method stub center = mGoogleMap.getCameraPosition().target; markerText.setText(" Set your Location "); mGoogleMap.clear(); markerLayout.setVisibility(View.VISIBLE); try { new GetLocationAsync(center.latitude, center.longitude) .execute(); } catch (Exception e) { } } }); markerLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub try { LatLng latLng1 = new LatLng(center.latitude, center.longitude); Marker m = mGoogleMap.addMarker(new MarkerOptions() .position(latLng1) .title(" Set your Location ") .snippet("") .icon(BitmapDescriptorFactory .fromResource(R.drawable.pin_last))); m.setDraggable(true); markerLayout.setVisibility(View.GONE); } catch (Exception e) { } } }); } catch (Exception e) { e.printStackTrace(); } } @Override public void onLocationChanged(Location location) { // TODO Auto-generated method stub } @Override public void onConnectionFailed(ConnectionResult arg0) { // TODO Auto-generated method stub } @Override public void onConnected(Bundle arg0) { // TODO Auto-generated method stub stupMap(); } private class GetLocationAsync extends AsyncTask<String, Void, String> { // boolean duplicateResponse; double x, y; StringBuilder str; public GetLocationAsync(double latitude, double longitude) { // TODO Auto-generated constructor stub x = latitude; y = longitude; } @Override protected void onPreExecute() { Address.setText(" Getting location "); } @Override protected String doInBackground(String... params) { try { geocoder = new Geocoder(MainActivity.this, Locale.ENGLISH); addresses = geocoder.getFromLocation(x, y, 1); str = new StringBuilder(); if (Geocoder.isPresent()) { Address returnAddress = addresses.get(0); String localityString = returnAddress.getLocality(); String city = returnAddress.getCountryName(); String region_code = returnAddress.getCountryCode(); String zipcode = returnAddress.getPostalCode(); str.append(localityString + ""); str.append(city + "" + region_code + ""); str.append(zipcode + ""); } else { } } catch (IOException e) { Log.e("tag", e.getMessage()); } return null; } @Override protected void onPostExecute(String result) { try { Address.setText(addresses.get(0).getAddressLine(0) + addresses.get(0).getAddressLine(1) + " "); } catch (Exception e) { e.printStackTrace(); } } @Override protected void onProgressUpdate(Void... values) { } } @Override public void onConnectionSuspended(int arg0) { // TODO Auto-generated method stub } }
哪里
GPSTracker
如下:public class GPSTracker extends Service implements LocationListener { private final FragmentActivity mActivity; // flag for GPS Status boolean isGPSEnabled = false; // flag for network status boolean isNetworkEnabled = false; boolean canGetLocation = false; Location location; double latitude; double longitude; // The minimum distance to change updates in metters private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 // metters // The minimum time beetwen updates in milliseconds private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1; // 1 minute // Declaring a Location Manager protected LocationManager locationManager; public GPSTracker(FragmentActivity activity) { this.mActivity = activity; getLocation(); } public Location getLocation() { try { locationManager = (LocationManager) mActivity .getSystemService(LOCATION_SERVICE); // getting GPS status isGPSEnabled = locationManager .isProviderEnabled(LocationManager.GPS_PROVIDER); // getting network status isNetworkEnabled = locationManager .isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (!isGPSEnabled && !isNetworkEnabled) { // no network provider is enabled } else { this.canGetLocation = true; // First get location from Network Provider if (isNetworkEnabled) { locationManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); if (locationManager != null) { location = locationManager .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); updateGPSCoordinates(); } } // if GPS Enabled get lat/long using GPS Services if (isGPSEnabled) { if (location == null) { locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); if (locationManager != null) { location = locationManager .getLastKnownLocation(LocationManager.GPS_PROVIDER); updateGPSCoordinates(); } } } } } catch (Exception e) { // e.printStackTrace(); Log.e("Error : Location", "Impossible to connect to LocationManager", e); } return location; } public void updateGPSCoordinates() { if (location != null) { latitude = location.getLatitude(); longitude = location.getLongitude(); } } /** * Stop using GPS listener Calling this function will stop using GPS in your * app */ public void stopUsingGPS() { if (locationManager != null) { locationManager.removeUpdates(GPSTracker.this); locationManager = null; } } /** * Function to get latitude */ public double getLatitude() { if (location != null) { latitude = location.getLatitude(); } return latitude; } /** * Function to get longitude */ public double getLongitude() { if (location != null) { longitude = location.getLongitude(); } return longitude; } /** * Function to check GPS/wifi enabled */ public boolean canGetLocation() { return this.canGetLocation; } /** * Function to show settings alert dialog */ public void showSettingsAlert() { if (mActivity == null || mActivity.isFinishing()) { return; } mActivity.runOnUiThread(new Runnable() { @Override public void run() { AlertDialog.Builder alertDialog = new AlertDialog.Builder( mActivity); // Setting Dialog Title alertDialog.setTitle("GPS is settings"); // Setting Dialog Message alertDialog .setMessage("Your GPS is disabled, Enable GPS in settings or continue with approximate location"); // On pressing Settings button alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS); mActivity.startActivity(intent); } }); // on pressing cancel button alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, int which) { // UserSerch doSerch = new UserSerch(); // doSerch.doserchOn(); // dialog.cancel(); } }); // Showing Alert Message alertDialog.create().show(); } }); } /** * Get list of address by latitude and longitude * * @return null or List<Address> */ public List<Address> getGeocoderAddress(Context context) { if (location != null) { Geocoder geocoder = new Geocoder(context, Locale.ENGLISH); try { List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1); return addresses; } catch (IOException e) { // e.printStackTrace(); Log.e("Error : Geocoder", "Impossible to connect to Geocoder", e); } } return null; } /** * Try to get AddressLine * * @return null or addressLine */ public String getAddressLine(Context context) { List<Address> addresses = getGeocoderAddress(context); if (addresses != null && addresses.size() > 0) { Address address = addresses.get(0); String addressLine = address.getAddressLine(0); return addressLine; } else { return null; } } /** * Try to get Locality * * @return null or locality */ public String getLocality(Context context) { List<Address> addresses = getGeocoderAddress(context); if (addresses != null && addresses.size() > 0) { Address address = addresses.get(0); String locality = address.getLocality(); return locality; } else { return null; } } /** * Try to get Postal Code * * @return null or postalCode */ public String getPostalCode(Context context) { List<Address> addresses = getGeocoderAddress(context); if (addresses != null && addresses.size() > 0) { Address address = addresses.get(0); String postalCode = address.getPostalCode(); return postalCode; } else { return null; } } /** * Try to get CountryName * * @return null or postalCode */ public String getCountryName(Context context) { List<Address> addresses = getGeocoderAddress(context); if (addresses != null && addresses.size() > 0) { Address address = addresses.get(0); String countryName = address.getCountryName(); return countryName; } else { return null; } } @Override public void onLocationChanged(Location location) { } @Override public void onProviderDisabled(String provider) { showSettingsAlert(); } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public IBinder onBind(Intent intent) { return null; } }
我希望它对任何人都有帮助。
- 2021-1-103 #
您可以尝试由我完成的此示例...。
我做的例子
activity_main.xml
<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" > <fragment android:id="@+id/map" android:name="com.rajeshvijayakumar.map.demo.ui.CustomMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" /> <include android:id="@+id/marker_view_incl" android:layout_width="match_parent" android:layout_height="match_parent" layout="@layout/marker_view" /> <include android:id="@+id/location_display_incl" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_margin="7dp" layout="@layout/location_display_view" /> </RelativeLayout>
marker_view.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageView android:id="@+id/marker_icon_view" android:layout_width="60dp" android:layout_height="60dp" android:layout_centerInParent="true" android:layout_marginTop="162dp" android:contentDescription="@string/app_name" android:src="@drawable/ic_launcher" /> </RelativeLayout>
location_display_view.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="60dp" android:background="@android:color/white" > <TextView android:id="@+id/text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:gravity="center" android:text="Set Location" android:textColor="@android:color/holo_green_dark" android:textSize="12sp" /> <TextView android:id="@+id/location_text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/text_view" android:layout_centerHorizontal="true" android:gravity="center" android:text="Set Location" android:textColor="@android:color/black" android:textSize="14sp" />
MapwrapperLayout.java
package com.rajeshvijayakumar.map.demo.wrapper; public class MapWrapperLayout extends FrameLayout { public interface OnDragListener { public void onDrag(MotionEvent motionEvent); } private OnDragListener mOnDragListener; public MapWrapperLayout(Context context) { super(context); } @Override public boolean dispatchTouchEvent(MotionEvent ev) { if (mOnDragListener != null) { mOnDragListener.onDrag(ev); } return super.dispatchTouchEvent(ev); } public void setOnDragListener(OnDragListener mOnDragListener) { this.mOnDragListener = mOnDragListener; } }
CustomMapFragment.java
package com.rajeshvijayakumar.map.demo.ui; public class CustomMapFragment extends MapFragment { private View mOriginalView; private MapWrapperLayout mMapWrapperLayout; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mOriginalView = super.onCreateView(inflater, container, savedInstanceState); mMapWrapperLayout = new MapWrapperLayout(getActivity()); mMapWrapperLayout.addView(mOriginalView); return mMapWrapperLayout; } @Override public View getView() { return mOriginalView; } public void setOnDragListener(MapWrapperLayout.OnDragListener onDragListener) { mMapWrapperLayout.setOnDragListener(onDragListener); } }
MainActivity.java
public class MainActivity extends Activity implements OnDragListener { // Google Map private GoogleMap googleMap; private CustomMapFragment mCustomMapFragment; private View mMarkerParentView; private ImageView mMarkerImageView; private int imageParentWidth = -1; private int imageParentHeight = -1; private int imageHeight = -1; private int centerX = -1; private int centerY = -1; private TextView mLocationTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // InitializeUI initializeUI(); } private void initializeUI() { try { // Loading map initilizeMap(); } catch (Exception e) { e.printStackTrace(); } mLocationTextView = (TextView) findViewById(R.id.location_text_view); mMarkerParentView = findViewById(R.id.marker_view_incl); mMarkerImageView = (ImageView) findViewById(R.id.marker_icon_view); } @Override public void onWindowFocusChanged(boolean hasFocus) { DisplayMetrics displaymetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); imageParentWidth = mMarkerParentView.getWidth(); imageParentHeight = mMarkerParentView.getHeight(); imageHeight = mMarkerImageView.getHeight(); centerX = imageParentWidth / 2; centerY = (imageParentHeight / 2) + (imageHeight / 2); } private void initilizeMap() { if (googleMap == null) { mCustomMapFragment = ((CustomMapFragment) getFragmentManager() .findFragmentById(R.id.map)); mCustomMapFragment.setOnDragListener(MainActivity.this); googleMap = mCustomMapFragment.getMap(); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getApplicationContext(), "Sorry! unable to create maps", Toast.LENGTH_SHORT) .show(); } } // CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, // 10); // googleMap.animateCamera(cameraUpdate); // locationManager.removeUpdates(this); } @Override protected void onResume() { super.onResume(); } @Override public void onDrag(MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_UP) { Projection projection = (googleMap != null && googleMap .getProjection() != null) ? googleMap.getProjection() : null; // if (projection != null) { LatLng centerLatLng = projection.fromScreenLocation(new Point( centerX, centerY)); updateLocation(centerLatLng); } } } private void updateLocation(LatLng centerLatLng) { if (centerLatLng != null) { Geocoder geocoder = new Geocoder(MainActivity.this, Locale.getDefault()); List<Address> addresses = new ArrayList<Address>(); try { addresses = geocoder.getFromLocation(centerLatLng.latitude, centerLatLng.longitude, 1); } catch (IOException e) { e.printStackTrace(); } if (addresses != null && addresses.size() > 0) { String addressIndex0 = (addresses.get(0).getAddressLine(0) != null) ? addresses .get(0).getAddressLine(0) : null; String addressIndex1 = (addresses.get(0).getAddressLine(1) != null) ? addresses .get(0).getAddressLine(1) : null; String addressIndex2 = (addresses.get(0).getAddressLine(2) != null) ? addresses .get(0).getAddressLine(2) : null; String addressIndex3 = (addresses.get(0).getAddressLine(3) != null) ? addresses .get(0).getAddressLine(3) : null; String completeAddress = addressIndex0 + "," + addressIndex1; if (addressIndex2 != null) { completeAddress += "," + addressIndex2; } if (addressIndex3 != null) { completeAddress += "," + addressIndex3; } if (completeAddress != null) { mLocationTextView.setText(completeAddress); } } } } }
- 2021-1-104 #
GPSClass From #Shvet ans.
public class CarSelectActivity extends BaseActivity implements GoogleApiClient.OnConnectionFailedListener, LocationListener, OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks { private GoogleApiClient mGoogleApiClient; private static final LatLngBounds BOUNDS_GREATER_SYDNEY = new LatLngBounds( new LatLng(-34.041458, 150.790100), new LatLng(-33.682247, 151.383362)); private GoogleMap mGoogleMap; private ImageView mMarkerImageView; private GPSTracker gps; @Override protected void onCreate(@Nullable final Bundle savedInstanceState) { super.onCreate(savedInstanceState); mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build(); setContentView(R.layout.activit_carselect); final SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); inilizviews(); } private void inilizviews() { gps = new GPSTracker(this); mMarkerImageView = (ImageView) findViewById(R.id.im_marker); } @Override public void onConnectionFailed(@NonNull final ConnectionResult connectionResult) { } @Override public void onLocationChanged(final Location location) { } @Override public void onMapReady(final GoogleMap googleMap) { mGoogleMap = googleMap; mGoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); mGoogleMap.getUiSettings().isMyLocationButtonEnabled(); mGoogleMap.getUiSettings().isZoomControlsEnabled(); mGoogleMap.getUiSettings().setMyLocationButtonEnabled(true); } @Override public void onConnected(@Nullable final Bundle bundle) { mGoogleApiClient.connect(); setUpDragListners(); } @Override public void onConnectionSuspended(int i) { } private void setUpDragListners() { if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } gps.canGetLocation(); LatLng curentpoint = new LatLng(gps.getLatitude(), gps.getLongitude()); CameraPosition cameraPosition = new CameraPosition.Builder() .target(curentpoint).zoom(15f).tilt(30).build(); mGoogleMap.setMyLocationEnabled(true); mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); mGoogleMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition arg0) { // TODO Auto-generated method stub LatLng center = mGoogleMap.getCameraPosition().target; try { getLocation(center.latitude, center.longitude); } catch (final Exception e) { e.printStackTrace(); } } }); private void getLocation(double latitude, double longitude) { Geocoder geocoder = new Geocoder(CarSelectActivity.this, Locale.ENGLISH); addresses = geocoder.getFromLocation(latitude, longitude, 1); textView_places.setText(addresses.get(0).getAddressLine(0) + addresses.get(0).getAddressLine(1) + " "); } }
相关问题
- android:Google Maps Fragment在片段内返回nullandroidgooglemapsandroidfragments2021-01-11 23:00
- android:如何在Google Map API v2中处理地图的onTouch事件?androidgooglemapsandroidmapviewgooglemapsandroidapi22021-01-11 18:57
- google maps:Android:如何捕获GPS位置图像androidgooglemapsgps2021-01-11 01:28
- Android Google Maps,如何使每个Marker Infowindow打开不同的Activity?androidgooglemaps2021-01-10 13:57
使用最新代码更新,还包括使用自动完成功能更改位置
完整的项目可以在这里找到
逻辑很简单,我们需要一个
framelayout
并在该framelayout
中添加地图和标记布局 然后使制造商将布局重力设为中心,并在相机更改时获取地图中心点的纬度和经度 参考这个答案 这是我的代码 创建activity_maps.xml创建
TextView
这里的backgound xml rounded_corner_map.xml这是我的活动类MainActivity.java
清单文件是