实现多边形与Android的谷歌地图API V2 [英] Implementing polygons with Google maps API V2 in Android

查看:200
本文介绍了实现多边形与Android的谷歌地图API V2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了在Android上的谷歌地图API V2,我得到了地图,以显示也是多边形使用该code,以显示:

 公共类MainActivity扩展FragmentActivity {
多边形多边形;
@覆盖
保护无效的onCreate(包savedInstanceState){

super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);

GoogleMap的GoogleMap的;
使用GoogleMap =((SupportMapFragment)(getSupportFragmentManager()findFragmentById(R.id.map))。)的GetMap()。
经纬度经纬度=新的经纬度(35.20418,-90.08342);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.addMarker(新MarkerOptions()
        .position(经纬度)
        .title伪(我的位置)
        是.snippet(这是我的位置!)
        .icon(BitmapDesc​​riptorFactory.defaultMarker(BitmapDesc​​riptorFactory.HUE_AZURE)));
googleMap.getUiSettings()setCompassEnabled(真)。
googleMap.getUiSettings()setZoomControlsEnabled(真)。
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(经纬度,10));

INT状态= GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
如果(状态== ConnectionResult.SUCCESS){
//成功!做你要做的

Log.i(服务,谷歌播放可用);
}
其他{
Log.i(服务,没有谷歌播放可用);
}

PolygonOptions rectOptions =新PolygonOptions()
。新增(新的经纬度(35.25010,-90.08342)
 新的经纬度(35.25010,-90.04175)
 新的经纬度(35.29177,-90.04175)
 新的经纬度(35.29177,-90.08342)
 新的经纬度(35.25010,-90.08342));


//设置矩形的笔触颜色为红色
 rectOptions.strokeColor(Color.BLUE);
//设置矩形的填充为蓝色
rectOptions.fillColor(Color.CYAN);
rectOptions.strokeWidth(2);
//找回可变多边形
多边形= googleMap.addPolygon(rectOptions);

}

}
 

在谷歌地图API V1的中的onTap 方法用于与多边形的交互。我的问题是什么让事件的onTap在VERSION2最好的方法是什么?我读过的谷歌Docs和,除非我错过了,我没有看到任何东西。

解决方案

使用的多边形和读取此链接

<$p$p><$c$c>https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/Polygon GoogleMap的地图;   多边形多边形= map.addPolygon(新PolygonOptions()  。新增(新经纬度(0,0),新经纬度(0,5),新经纬度(3,5),新经纬度(0,0))  .strokeColor(Color.RED)  .fillColor(Color.BLUE));

I implemented the Google maps API V2 on Android, I got the map to show and also the polygon to show using this code:

public class MainActivity extends FragmentActivity {
Polygon polygon;
@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

GoogleMap googleMap;
googleMap = ((SupportMapFragment)(getSupportFragmentManager().findFragmentById(R.id.map))).getMap();
LatLng latLng = new LatLng(35.20418,-90.08342);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.addMarker(new MarkerOptions()
        .position(latLng)
        .title("My Spot")
        .snippet("This is my spot!")
        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
googleMap.getUiSettings().setCompassEnabled(true);
googleMap.getUiSettings().setZoomControlsEnabled(true);
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 10));

int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if(status == ConnectionResult.SUCCESS) {
//Success! Do what you want

Log.i("service", "Google play available");
}
else{
Log.i("service", "No Google play available");
}

PolygonOptions rectOptions = new PolygonOptions()
.add(new LatLng(35.25010,-90.08342),
 new LatLng(35.25010,-90.04175),
 new LatLng(35.29177,-90.04175),
 new LatLng(35.29177,-90.08342),
 new LatLng(35.25010,-90.08342));


//Set the rectangle's stroke color to red
 rectOptions.strokeColor(Color.BLUE);
//Set the rectangle's fill to blue
rectOptions.fillColor(Color.CYAN);
rectOptions.strokeWidth(2);
//Get back the mutable Polygon
polygon = googleMap.addPolygon(rectOptions);

}

}

On the Google map API V1 the onTap method is used to interact with the polygon. My question is what's the best way to get onTap events in version2? I've read the Google docs and unless I missed it, I did not see anything on it.

解决方案

use this for Polygon and read this link

https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/Polygon

GoogleMap map;

  Polygon polygon = map.addPolygon(new PolygonOptions()
 .add(new LatLng(0, 0), new LatLng(0, 5), new LatLng(3, 5), new LatLng(0, 0))
 .strokeColor(Color.RED)
 .fillColor(Color.BLUE));

这篇关于实现多边形与Android的谷歌地图API V2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆