Android Google Map to show as picture

后端 未结 2 1585
慢半拍i
慢半拍i 2021-01-30 09:53

I\'ve implemented Google Maps V2 in my android app and now I would like to do something differently. I\'m showing a location (longitude, latitude) with a marker. The problem is

2条回答
  •  感情败类
    2021-01-30 10:06

    There is a slightly different option that can achieve the same result and requires very little coding, provided your app can use the network: you can call the Google Static Maps API to ask for an map image with arbitrary center, zoom level, size, and other features such as markers and paths.

    For example the link:

    https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=14&size=600x300

    produces the following image:

    enter image description here

    This makes it very easy to display a map in an ImageView widget: you just need to build the appropriate URL from the location data and dimensions, and then display the image with any of the image loading frameworks such as Picasso, Volley, &c. We've using this feature for a couple of years now.

    This is especially useful when displaying, say, a ListView of little maps. In those situations, asking for n snapshots will be problematic, while n image downloads should work just fine.


    A third option, which will become available in the next week or so, according to this announcement, is the new Lite Maps mode which will be released as part of Google Play Services 6.5:

    In addition, there is also a new ‘lite mode’ map option, ideal for situations where you want to provide a number of smaller maps, or a map that is so small that meaningful interaction is impractical, such as a thumbnail in a list. A lite mode map is a bitmap image of a map at a specified location and zoom level.

    In lite mode, markers and shapes are drawn client-side on top of the static image, so you still have full control over them. Lite mode supports all of the map types, the My Location layer, and a subset of the functionality of a fully-interactive map.

    Sounds exactly like what you need, provided you can wait a few days for the updated SDK. :)

提交回复
热议问题