根据经纬度在谷歌地图上绘制路径 [英] Draw path on google map based on lat lang

查看:738
本文介绍了根据经纬度在谷歌地图上绘制路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



基本上我是在特定时间间隔后跟踪用户位置的。当用户到达某个目的地时,我需要绘制他到达目的地的路径。

它工作正常,但问题在于它显示的是之字形路径。



我想要的是什么:

一个正确的路径,跟踪我在追踪过程中得到的要点。



我曾尝试



我搜索并找到了

解决方案

我同意antonio 的答案。问题不在于你绘画功能。你只需绘制路径,无论设备给你的位置。问题是您的设备没有提供准确的位置。



让我简要介绍一下位置功能。<​​/ p>

有三种供应商在设备上提供位置。



1 GPS提供商。



卫星。根据条件,此提供程序可能需要一段时间才能返回定位修复。需要许可ACCESS_FINE_LOCATION。



GPS位置提供商的附加包可包含以下键/值对:

<卫星数 - 用于导出定位的卫星数量

2网络提供商



该提供商确定基于小区塔和WiFi接入点的可用性的位置。通过网络查找检索结果。

3被动提供者。



当其他应用程序或服务请求时,此提供程序可用于被动接收位置更新他们没有实际要求你自己的位置。该提供者将返回由其他提供者生成的位置。您可以查询getProvider()方法以确定位置更新的来源。需要ACCESS_FINE_LOCATION权限,但如果未启用GPS,则此提供程序可能只返回粗略修正。

参考:

Android位置管理器

Android位置提供商 - GPS或网络提供商?
$ b


根据我的经验,我可以说 GPS提供商可为您提供准确的
地点与网络提供商但需要开放环境, GPS
提供者
在内部建筑物中没有提供准确的位置。




getAccuracy()。



返回描述此提供者水平精度的常量。如果提供者返回更精细的谷物或确切位置,则返回 ACCURACY_FINE ,否则如果位置仅为近似值,则 ACCURACY_COARSE 为回。



当GPS位置改变时,此方法将返回确切值,否则它将返回近似值或0值。

Ref: Location.getAccuracy()



解决方案:
$ b


  1. 仅使用GPS提供商

  2. 找出您的位置是否准确。

  3. 推荐使用Google客户端
    示例。


    i want to draw path on google map.

    Basically what i am tracking user locaion after specfic time interval. when user reach to some destination then i need to draw the path which he followed to reach that destination.

    It is working fine but the problem is it is showing zigzag path. See the image below.

    What i want:

    I want to draw a proper path followed by the points that i get during tracking.

    What i have tried

    i searched and found this link in which we can pass up to 8 points to get the directions. Which is the maximum limit allowed to the non-business users of the Google Map. Is there any other way to achieve this. because i have so many points to draw on map.

    code for drawing polylines

    private void drawPath() {
            if (mMap != null)
                mMap.clear();
            int count = 0;
            LatLng prev = null;
            String[] mProjection = {LocTable.COLUMN_ID, LocTable.COLUMN_LONGITUDE, LocTable.COLUMN_LATITUDE};
            String mSelectionClause = LocTable.COLUMN_ID + "> ?";
            String[] mSelectionArgs = {"0"};
            String mSortOrder = LocTable.COLUMN_ID;
    
            Cursor mCursor = getContentResolver().query(
                    LocContentProvider.CONTENT_URI,   // The content URI of the words table
                    mProjection,                        // The columns to return for each row
                    mSelectionClause,                    // Selection criteria
                    mSelectionArgs,                     // Selection criteria
                    mSortOrder); 
    
    
            if(mCursor != null && mCursor.getCount()!=0) {
    
                Log.i("cursor", "Count: " + mCursor.getCount() + "|Column count: " + mCursor.getColumnCount());
                if (mCursor.moveToFirst()) {
                    do {
                        if (mMap != null) {
    
                            float lon = mCursor.getFloat(1);
                            float lat = mCursor.getFloat(2);
                            LatLng current = new LatLng(lat, lon);
    
                            markerPoints.add(current);
                            if (count == 0){
                                prev = current;
                            }
                            CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(current, 19);
                            mMap.animateCamera(cameraUpdate);
                            mMap.addPolyline((new PolylineOptions())
                                    .add(prev, current).width(6).color(Color.BLUE)
                                    .visible(true));
                            prev=current;
                            count++;
                        }
                    } while (mCursor.moveToNext());
                }
    
                mCursor.close();
            }
        }
    

    thanks for help.

    解决方案

    I'm agree with antonio's answer. Problem is not with you drawing function. You just drawing path whatever device giving you location. Problem is your device is not giving accurate location.

    Let me giving you brief description about Location Functionality.

    There are three kind of provider giving location in device.

    1 GPS Provider.

    This provider determines location using satellites. Depending on conditions, this provider may take a while to return a location fix. Requires the permission ACCESS_FINE_LOCATION.

    The extras Bundle for the GPS location provider can contain the following key/value pairs:

    satellites - the number of satellites used to derive the fix

    2 Network Provider.

    This provider determines location based on availability of cell tower and WiFi access points. Results are retrieved by means of a network lookup.

    3 Passive Provider.

    This provider can be used to passively receive location updates when other applications or services request them without actually requesting the locations yourself. This provider will return locations generated by other providers. You can query the getProvider() method to determine the origin of the location update. Requires the permission ACCESS_FINE_LOCATION, although if the GPS is not enabled this provider might only return coarse fixes.

    Reference:

    Android Location Manager

    Android Location Providers - GPS or Network Provider?

    As per my experience I can say GPS Provider is giving you accurate location compare to Network Provider but need open environment, GPS provider is not giving accurate location in inside building.

    getAccuracy().

    Returns a constant describing horizontal accuracy of this provider. If the provider returns finer grain or exact location, ACCURACY_FINE is returned, otherwise if the location is only approximate then ACCURACY_COARSE is returned.

    This method will return exact value when location is changed from GPS Provider otherwise it will return approximate or 0 value.

    Ref : Location.getAccuracy()

    Solution:

    1. Use only GPS Provider

    2. Find out your location is accurate or not.

    Recommended Use Google Client Sample Example.

    这篇关于根据经纬度在谷歌地图上绘制路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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