Relocate Google logo in MapView

2019-01-11 13:38发布

问题:

I have two buttons at each bottom corners of the MapView, partly obscuring the google logo in the bottom-left corner.

In order to comply with the terms and conditions of the API, I need to relocate the google logo to somewhere more visible. i.e. above the button.

The google API doc states that the google logo is drawn in the onDraw() method of MapView but I have no idea how to override it properly since google maps is closed source.

I could do this in iPhone by finding the correct UIView in the MKMapView's children but I can't figure out how I could do this in Android.

回答1:

Google Maps SDK v2 for Android adds this functionality.

Use GoogleMap.setPadding() to add padding to the "active" area (including the Google logo and copyright notices) while still filling the full container.

https://developers.google.com/maps/documentation/android/map#map_padding



回答2:

I had the same issue, but you can achieve what you want without conflicting with Google's Terms and Conditions. The main thing is to put your mapView in a Frame layout, such as this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"     
 android:orientation="vertical" >          

 <FrameLayout android:id="@+id/map_frame"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_weight="0.7" >     

    <com.google.android.maps.MapView
        android:id="@+id/map_view" 
        android:layout_width="fill_parent"
        android:layout_height="match_parent" 
        android:enabled="true" 
        android:clickable="true"             
        android:apiKey="mySecretMapsApiKey"/>

 </FrameLayout>

 <ws.mentis.android.guardian.ui.MapNavBar
    android:id="@+id/map_nav"
    android:layout_width="fill_parent"
    android:layout_height="70dip"
    android:layout_gravity="bottom"
    android:layout_weight="0.3" /> 

 </LinearLayout>

I had a number of buttons to included, so I created them in a custom widget (MapNavBar). As you can see from the screen shot, the Google logo is still visible and in its normal place, within the new window.

This is working in Android 2.2 It also has the benefit that the standard zoom control also moves up so it doesn't interfere with your own buttons.



回答3:

You can move the google logo with the help of the Tag assigned to it GoogleWatermark. In the below code i have moved it to top right corner of the screen.

View googleLogo = binding.missionMap.findViewWithTag("GoogleWatermark");
RelativeLayout.LayoutParams glLayoutParams = (RelativeLayout.LayoutParams)googleLogo.getLayoutParams();
glLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0);
glLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
glLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_START, 0);
glLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
glLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_END, RelativeLayout.TRUE);
googleLogo.setLayoutParams(glLayoutParams);

where missionMap is the framelayout to which the MapFragment has been added.



回答4:

From the documentation :

protected final void onDraw(android.graphics.Canvas canvas)

onDraw is final method. This can't be overridden at all.

You can alternatively, show your buttons below mapview in layout aligned to parent bottom. This way you can have buttons at the position where you like and it will not obscure your google logo.



回答5:

Really old question, but maybe someone will make use of it. I made it to appear in right upper corner:

Rect rect = new Rect()
mMapView.getLocalVisibleRect(rect)
googleMap.setPadding(rect.width() - 100, 0, 0, rect.height() - 50)

If you want to place it somewhere else, you will need to have fun with setPadding

Also don't forget to hide UI buttons of google maps:

googleMap.getUiSettings().setMapToolbarEnabled(false)
googleMap.getUiSettings().setZoomControlsEnabled(false)
googleMap.getUiSettings().setMyLocationButtonEnabled(false)

There is one (at least) problem. When using camera to center map on given point will not work properly. If camera movement is needed it will be better to just set padding to visible map fragment and it should work properly. Use rect to know what dimensions to put into setPadding



回答6:

Kind of a hack, but you could try add a MapView it to a FrameLayout, setting the height of the MapView X dp larger than the FrameLayout so it gets clipped off, and adding a Logo Drawable wherever you wanted it to be.



回答7:

You don't have anything to do but using padding on GoogleMap object as stated by google maps documentation Note: As per the Google Maps Platform Terms of Service, your application must not remove or obscure the Google logo or copyright notices. Map padding allows you to reposition these elements if necessary. If you display a custom UI at the bottom of the map, add padding to the bottom of the map so that the logo and legal notices will always be visible.