本文介绍了圈绘制看起来像在地图上的椭圆形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我想在地图上创建圆形。对于我使用地面覆盖项目。我试着画圆形形状绘制xml文件。首先,我尝试了正常的活动布局,它让我完美的圆形。同样的事情我试着画在地图上,它看起来像椭圆形。我的code的绘制和布局如下:

Hi I am trying create circle shape on map. For that i am using ground overlay item. I tried draw circle shape with drawable xml file. First I tried in normal activity layout and it shows me perfect circle shape. same thing I tried to draw on map it looks like oval shape. My code for drawable and layout is as follows :

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

   <solid 
       android:color="#666666"/>

   <size 
       android:width="120dp"
    android:height="120dp"/>
</shape>

和我的布局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <RelativeLayout 
    android:id="@+id/circleLay"
    android:layout_height="100dp"
    android:layout_width="100dp"
    android:layout_centerInParent="true"
    android:background="@drawable/circle">
    </RelativeLayout>

</RelativeLayout>

我试图创建地面叠加的项目如下:

I tried to create ground overlay item as follows :

LatLng NEWARK = new LatLng(0, 0);
        View markerView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.custom_marker_layout, null);
        GroundOverlayOptions newarkMap = new GroundOverlayOptions()
                .image(BitmapDescriptorFactory.fromBitmap(createDrawableFromView(this, markerView)))
                .position(NEWARK, 860000f, 650000f);
GroundOverlay imageOverlay = googleMap.addGroundOverlay(newarkMap);

我试过的活动,显示我的圈子,但在地图显示它椭圆形,没有圆形同样的事情。如何做到这一点?需要帮忙。谢谢你。

same thing I tried for activity which shows me circle but for map it showing oval shape not circle shape. How to do this? Need Help. Thank you.

推荐答案

您可以简单地添加一个圈直接,而是采用了的GroundOverlay

You could simply add a Circle directly, instead of using a GroundOverlay:

Circle circle = googleMap.addCircle(new CircleOptions()
     .center(new LatLng(40.740234,-74.171505))
     .radius(10000)
     .strokeColor(Color.GRAY)
     .fillColor(Color.GRAY));

这篇关于圈绘制看起来像在地图上的椭圆形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 05:24