如何为Google Glass创建黑暗的Google地图图像?

Ton*_*ato 4 google-maps-static-api google-glass google-gdk

我需要在Google Glass上创建一个暗/倒映射图像,因为标准的Google静态地图图像在屏幕上显示时太亮了.如何自定义地图主题以在Glass上看起来很好?

Ton*_*ato 8

Google Static Maps API提供了许多自定义选项来更改地图功能的颜色.下面是一个活动的示例,该活动加载暗/倒置静态地图图像并ImageView在Glass上以全屏显示.

用于构建URL的查询参数的说明可以在Google Maps Static Maps API文档中找到.

public class StaticMapActivity extends Activity {

    private static final String TAG = StaticMapActivity.class.getSimpleName();

    private static final String STATIC_MAP_URL_TEMPLATE =
            "https://maps.googleapis.com/maps/api/staticmap"
            + "?center=%.5f,%.5f"
            + "&zoom=%d"
            + "&sensor=true"
            + "&size=640x360"
            + "&scale=1"
            + "&style=element:geometry%%7Cinvert_lightness:true"
            + "&style=feature:landscape.natural.terrain%%7Celement:geometry%%7Cvisibility:on"
            + "&style=feature:landscape%%7Celement:geometry.fill%%7Ccolor:0x303030"
            + "&style=feature:poi%%7Celement:geometry.fill%%7Ccolor:0x404040"
            + "&style=feature:poi.park%%7Celement:geometry.fill%%7Ccolor:0x0a330a"
            + "&style=feature:water%%7Celement:geometry%%7Ccolor:0x00003a"
            + "&style=feature:transit%%7Celement:geometry%%7Cvisibility:on%%7Ccolor:0x101010"
            + "&style=feature:road%%7Celement:geometry.stroke%%7Cvisibility:on"
            + "&style=feature:road.local%%7Celement:geometry.fill%%7Ccolor:0x606060"
            + "&style=feature:road.arterial%%7Celement:geometry.fill%%7Ccolor:0x888888";

    /** Formats a Google static maps URL for the specified location and zoom level. */
    private static String makeStaticMapsUrl(double latitude, double longitude, int zoom) {
        return String.format(STATIC_MAP_URL_TEMPLATE, latitude, longitude, zoom);
    }

    private ImageView mMapView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mMapView = new ImageView(this);
        setContentView(mMapView);

        loadMap(37.8019, -122.4189, 18);
    }

    /** Load the map asynchronously and populate the ImageView when it's loaded. */
    private void loadMap(double latitude, double longitude, int zoom) {
        String url = makeStaticMapsUrl(latitude, longitude, zoom);
        new AsyncTask<String, Void, Bitmap>() {
            @Override
            protected Bitmap doInBackground(String... urls) {
                try {
                    HttpResponse response = new DefaultHttpClient().execute(new HttpGet(urls[0]));
                    InputStream is = response.getEntity().getContent();
                    return BitmapFactory.decodeStream(is);
                } catch (Exception e) {
                    Log.e(TAG, "Failed to load image", e);
                    return null;
                }
            }

            @Override
            protected void onPostExecute(Bitmap bitmap) {
                if (bitmap != null) {
                    mMapView.setImageBitmap(bitmap);
                }
            }
        }.execute(url);
    }
}
Run Code Online (Sandbox Code Playgroud)