Android the Google Maps polyline layer (Polyline)

2010-07-17  来源:本站原创  分类:Mobile  人气:271 

My project needs planning Android Google Map on the line, found that API, there is not even Polyline, analysis Overlay class, his class made a line, to use the Polyline with Flex is similar to the remaining few that directly paste the code.

package westyi.map.overlay;

import java.util.List;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

/**
 * Goolge Map of Polyline implementation
 *
 * @author westyi
 */
public class Polyline extends Overlay {
        List<GeoPoint> points;
        Paint paint;

        /**
         *  Constructor, use the  GeoPoint List Constructor  Polyline
         *
         * @param points
         *            GeoPoint Point  List
         */
        public Polyline(List<GeoPoint> points) {
                this.points = points;
                paint = new Paint();
                paint.setColor(Color.BLUE);
                paint.setAlpha(150);
                paint.setAntiAlias(true);
                paint.setStyle(Paint.Style.FILL_AND_STROKE);
                paint.setStrokeWidth(4);
        }

        /**
         *  Use the GeoPoint points  List And the Paint object to construct the  Polyline
         *
         * @param points
         *            GeoPoint Points of inflection point List, all
         * @param paint
         *            Paint Object, used to control the dash style
         */
        public Polyline(List<GeoPoint> points, Paint paint) {
                this.points = points;
                this.paint = paint;
        }

        /**
         *  True to draw the line from the line is drawn to the  canvas Can be, primarily to convert latitude and longitude coordinates to screen
         */
        @Override
        public void draw(Canvas canvas, MapView mapView, boolean shadow) {
                if (!shadow) {//  Draw the shadow layer is not
                        Projection projection = mapView.getProjection();
                        if (points != null) {
                                if (points.size() >= 2) {
                                        Point start = projection.toPixels(points.get(0), null);//  Need to convert coordinates
                                        for (int i = 1; i < points.size(); i++) {
                                                Point end = projection.toPixels(points.get(i), null);
                                                canvas.drawLine(start.x, start.y, end.x, end.y, paint);//  Can be drawn to the canvas
                                                start = end;
                                        }
                                }
                        }
                }
        }
}

Using a simple example follows:

List<GeoPoint> points = new ArrayList<GeoPoint>();
points.add(new GeoPoint(39907794,116356694));
points.add(new GeoPoint(39950181,116415059));
points.add(new GeoPoint(39909637,116435315));
points.add(new GeoPoint(39902526,116398236));
Polyline polyline = new Polyline(points);
map.getOverlays().add(polyline); //map The type is a MapView
map.invalidate();

OK, you're done! See the effect as follows:

Android the Google Maps polyline layer (Polyline)

相关文章
  • Android the Google Maps polyline layer (Polyline) 2010-07-17

    My project needs planning Android Google Map on the line, found that API, there is not even Polyline, analysis Overlay class, his class made a line, to use the Polyline with Flex is similar to the remaining few that directly paste the code. package w

  • Android's Google Maps to upgrade to version 4.4 focus on increasing the search function near 2010-07-29

    Ready for the sixth time since last six months of Android version of Google Maps to upgrade the! Google will lead the online map to a new area, especially for understanding of their environment! The upgrade includes new features as Place, allows user

  • [Android] Google Maps application. Set up and use 2010-10-12

    Location location services using mobile devices more and more red, many people have a lot of interesting ideas, such as query by Location around the business location information, the location of photos into easy to share and record the latitude and

  • Android Development Study Notes (b): Google Maps preliminary 2010-12-22

    First of all, I write this thing is not a "tutorial" as the so-called tutorial keep up the book, step by step, progressive approach. And my "notes" is more like a "problem solution set." Encountered in project development to

  • Google Maps Android API v2 简介 2013-11-29

    通过Google Maps Android API,你可以给你的应用程序添加基于Google Maps数据的地图.那些API自动处理对于Google Maps服务器的访问,数据下载,地图显示,及对地图手势的相应.你也可以使用API调用来给一个基本的地图添加markers,polygons,和overlays,及改变一个特定的地图区域的用户视图.这些对象为地图位置提供了额外的信息,并允许用户与地图进行交互.这些API使你可以给一幅地图添加这样的一些图形: 固定在地图上特定位置的图标(Markers

  • Google Maps Android API v2入门 2013-11-30

    概述 创建一个新的使用了Google Maps Android API v2的Android应用需要许多个步骤.这一节中所概述的其中的许多步骤只是需要必须执行一次而已,但有些信息则是未来应用开发方便的参考.给一个Android应用程序添加一个地图的总体过程如下: 安装Android SDK. 下载并配置Google Play services SDK,其中包含了Google Maps Android API.如果你使用了商业Google Maps Mobile SDK,则你必须下载并配置商业Go

  • Google Maps API v2 android版本开发 国内手机不支持google play 2014-03-14

    Google Maps API v2 android版本开发 国内手机不支持google play Service相关问题解决--图文教程 移步:http://www.cnblogs.com/zdz8207/archive/2013/03/25/android-google-maps-api-v2.html https://code.google.com/apis/console/b/1/?noredirect&pli=1

  • Google Maps Android API v2与高德Android SDK能力差异 2014-11-28

    废话不多说,感觉最明显的几点差异: 1.Google Maps Android API v2提供了高德所没有的室内.街景能力: 2.Google没有提供离线地图下载的功能: 3.Google没有提供路线规划以及导航的能力: 4.Google提供的Overlay只限于GroundOverlay以及TileOverlay,没有看到像高德那种POIOverlay.RouteOerlay这种; 5.没有提供poi检索的能力,不过这个好像在Google Places API中.

  • Google Maps Javascript API V3 Reference 2010-07-30

    Google Maps Javascript API V3 Reference Reference Table of Contents Map : MapOptions MapTypeId MapTypeControlOptions MapTypeControlStyle NavigationControlOptions NavigationControlStyle ScaleControlOptions ScaleControlStyle ControlPosition MapPanes Ma

  • Google Maps Street View full screen shortcut 2010-04-12

    Google Maps Street View support for keyboard shortcuts (via Amit): a left or right arrow keys to>> rotate 45 degrees counterclockwise d or right arrow keys to>> rotate 45 degrees clockwise The arrow keys to>> forward (only under the defa

  • Android uses Google Map API to create a program based on latitude and longitude of a location 2010-10-25

    Realize the function is to enter longitude and latitude of the location in the concrete realization of the map shown as follows: Get Google Maps API key 1 To use Google's Maps API, Google must get from a Google Maps API key. Obtained as follows: (1)

  • ArcGIS Server flex to load Google Maps 2011-08-15

    ArcGIS Server flex to load google maps, no longer a technical issue. But today with the project, and project data base map coordinate system has not matched. Even if the matches, but also reach the precision problem. Finally, and more dedication to b

  • Google Maps Navigation 2009-11-27

    Google Maps Navigation 网站 : http://www.google.com/maps/about/ Google Maps Navigation 是谷歌公司推出的基于 Android 2.0 的一款导航软件(非开源),目前据称也支持 Android 1.6 . Google Maps Navigation仅仅是Android 2.0系统里的一个应用,但它将Google的诸多技术整合在一起,包括Google Maps,Google Street View.语音识别.交通流量

  • UIQ手机专用Google Maps移动版终于发布 2014-02-17

    用过不少手机平台,始终有个遗憾.比如索爱智能手机常用的UIQ平台,尽管在触控操作上有优势,性能也不错,但应用程序实在太少了,因此我最后还是转向了Symbian S60.就拿Google的各种移动产品为例,真正有原生UIQ版本的并不多.之前试过在UIQ上安装并运行通用版的Google Maps移动版,速度慢得惊人.但如果你现在还坚守在UIQ平台上,有好消息了.至少,Google现在终于发布了UIQ平台专用的Google Maps移动版. 这意味着UIQ平台(3.0版及以上)的手机像索爱P1.W96

  • 黑莓版Google Maps 4.0增语音搜索.Buzz 2014-06-20

    来自Google移动官方博客的消息,黑莓版手机地图应用Google Maps现在已经更新至4.0版本,新增了包括语音搜索.Buzz等功能. 现在用户只需按住界面中绿色呼叫按钮并说话,手机可以将语音转换问文本并在地图中进行搜,当结果出现后用户也可以选择收取相关信息,目前这项功能支持英语和中文等多种语言. Google Buzz也将以新图层的方式出现在Maps中,通过添加Buzz图层就可以看到好友在附近发布的Buzz信息,用户也可以使用该功能发布基于位置的状态信息. 此外,黑莓版Google Map

  • Google Maps API第三版发布 2014-07-26

    据Google Geo Developers Blog报道,自从上次在三年前发布了基于JavaScript的Google Maps API后,已经有大约15万个活跃网站正在使用这个API,Google Maps API已经成为最流行和最可信赖的网络开发工具,现在,Google地图API进行了重大的改版,用户现在可以在Google Code Labs中使用第三版的地图API应用. 新版本的API主要特点是提高了速度,特别是对于手机浏览器的渲染速度,去年Google就开始思考在移动设备上运行地图AP

  • ASP.NET中使用Google Maps API V3 2015-02-12

    写在最前面 早就听说过Google Maps API了,但一直没用过,今天在CodeProject上看到了这篇关于Google Maps API(V3版本)使用的文章,觉得很容易上手,就将他翻译下来了,相信对初学者会有大的帮助.译文允许转载,但请在页面明显处标明以下信息,且保留完整原文链接地址和译文链接地址,谢谢合作! 简介 Google Maps为我们提供了一种非常灵活的方式来使用它的地图服务.我们可以在Web应用程序中通过调用Google Maps API来为我们的用户提供方位信息.地理位置

  • 谷歌推出企业版地图服务Google Maps Engine Pro 2015-05-04

    据谷歌地理博客报道,Google推出企业版地图工具Google Maps Engine Pro,让企业可以在Google地图进行资料分析及视觉化.据悉,Google推出试用帐号服务让企业免费申请试用,它具备Google Maps Engine完整功能,但限制地图查询次数. 这是一款基于云计算的软件工具,专门帮助企业组织送货路径.仓库位置.销售区域等数据,以便弥补电子表格和庞大数据库的不足. 该工具是为了解决众多与地理位置相关的问题:通过在地图上了解员工居住的地点来更好地设计班车路线,或是在地图上

  • Google Maps API on CM11 2014-11-27

    CM11基于安卓原生4.4.2进行的修改,如果现在使用Google Maps API进行地图的开发应该如何做?关于Google play service的使用网上已经有很多教程了,无外乎刷zip包或者单独push apk之类.可以从网上下载内容很全的zip包,基本上把所有的google 服务apk都包含在内了,但是如果我只想使用map api最少需要哪些依赖呢? 1.com.google.android.map.jar,将此jar包push到/system/framework/下: 2.有了ja

  • Flex in Flash through the use of Google Maps 2009-04-22

    Put Google map embedded into web pages has now very easy to use API of Google Maps can be manipulated through JavaScript. But sometimes we need to come from Google's map service is embedded in Flash, this time should not the easy use of JavaScript. F