【问题标题】:addMarker Google Maps Option is not displayingaddMarker Google 地图选项未显示
【发布时间】:2015-06-09 09:39:04
【问题描述】:

我正在使用异步任务来查询我的数据库并填充包含两个双精度值的包裹对象的 ArrayList,一个用于经度和纬度。

    ArrayList<parcels> mPoints = new ArrayList<parcels> ();

然而,当我添加我的标记时,什么都没有显示,但我的所有调试消息都被执行,说明一切运行良好。但是当我看时,我的地图上没有标记。我是 android 新手,也是 java 新手。

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        if(mPoints != null){
            //set points
            if(mMap == null){
                Log.d("JakeDebug", "map is null");


            }
            for(int i=0; i < mPoints.size(); i++){
                parcels tmp = mPoints.get(i);
                Log.d("JakeDebug", "marker at " + tmp.longitude +","+ tmp.latitude);
                mMap.addMarker(new MarkerOptions().position(new LatLng(tmp.latitude, -(tmp.longitude))).title(tmp.name).visible(true));
                //mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(tmp.latitude, tmp.longitude), 15));
                Log.d("JakeDebug", "Adding marker");

            }

        } else{
            Log.d("JakeDebug", " mPoints is null");


        }

我的输出调试:

06-08 09:41:39.599    3165-3182/teaminfamous.com.friendsend D/JakeDebug﹕ GetPackagesQuery:
06-08 09:41:39.720    3165-3182/teaminfamous.com.friendsend D/JakeDebug﹕ AddPackageQuery: just before query
06-08 09:41:39.720    3165-3182/teaminfamous.com.friendsend D/JakeDebug﹕ AddPackageQuery: query = "SELECT name, long, lat FROM _parcels_ where id=1"
06-08 09:41:39.728    3165-3182/teaminfamous.com.friendsend D/JakeDebug﹕ Login Query: empty = true
06-08 09:41:39.728    3165-3182/teaminfamous.com.friendsend D/JakeDebug﹕ just after query
06-08 09:41:40.337    3165-3165/teaminfamous.com.friendsend D/JakeDebug﹕ marker at 38.5539,121.7381
06-08 09:41:40.342    3165-3165/teaminfamous.com.friendsend D/JakeDebug﹕ Adding marker

【问题讨论】:

  • 你什么时候执行异步任务?
  • 地图设置完成后,我在我的 onCreate 中执行它。我检查了是否设置了地图,并且数组已初始化并且内部数据库中有适当的项目。我不应该在 onCreate 中这样做吗?

标签: java android google-maps


【解决方案1】:

在意识到我的数字被翻转然后放大我看到标记后,你似乎必须放大到那个确切的位置!

 for(int i=0; i < mPoints.size(); i++){
                    parcels tmp = mPoints.get(i);
                    Log.d("JakeDebug", "marker at " + tmp.longitude +","+ tmp.latitude);
                    mMap.addMarker(new MarkerOptions().position(new LatLng(tmp.longitude, -(tmp.latitude))).title(tmp.name).visible(true));
                    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(tmp.longitude, -(tmp.latitude)), 14));
                    Log.d("JakeDebug", "Adding marker");

                }

因此,如果您没有看到标记,请务必移动相机并放大它。这可能是问题所在,还要确保您的号码顺序正确!

【讨论】:

  • 我在翻转数字时遇到了同样的问题,但放大了很多,一次找不到标记...
  • 是的哈哈,你认为它只是显示标记而不放大,但它可能又一次,我只是不知道我在做什么哈哈
猜你喜欢
  • 2014-08-01
  • 2016-11-22
  • 1970-01-01
  • 2017-04-06
  • 2018-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多