在数据库中的Google地图(API V2)上显示多个标记

编码率

大家好,我想在我的Google地图屏幕上显示多个标记。我正在数据库中存储经纬度测试名称值。我可以从数据库中获取结果,但是在Google地图上看不到图钉。

这是正在返回游标的数据库方法。

public Cursor getPinFromDatabase(String testType)
{
    Cursor results = null;
    try{
        mDatabase = mDbHelper.getReadableDatabase();
        String selection = GLNetTestDataContract.TestPinRecord.COLUMN_NAME_TESTTYPE + "=?";
        // Specify arguments in placeholder order.
        String[] selectionArgs = { String.valueOf(testType)};
        results = mDatabase.query(GLNetTestDataContract.TestPinRecord.TABLE_NAME, null, selection, selectionArgs, null, null, null);
        results.moveToFirst();
        do
        {
            mLogger.printLog("pin","TestName : "+results.getString(1));
            mLogger.printLog("pin","TestType : "+results.getString(2));
            mLogger.printLog("pin","Latitude : "+results.getString(3));
            mLogger.printLog("pin","Longitude: "+results.getString(4));
        }while(results.moveToNext());           
    }
    catch(Exception e)
    {
        mLogger.printLog("pin", "Exception in TestPinRecordHandler->>getPinFromDatabase");
        mLogger.printLog("pin", e.getLocalizedMessage());
    }
    finally{
        mDatabase.close();
        return results;
    }

}

}

此方法负责在地图setPinOnMap()上设置图钉

public void setPinOnMap(){
        try{
            Cursor pinRecordCursor = mTestPinRecordHandler.getPinFromDatabase("Manual");
            mPinMarkerList = new ArrayList<PinMarker>();
            if(pinRecordCursor != null && pinRecordCursor.moveToFirst())
            {
                do
                {//String testName, String testType, String latitude, String longitude
                    PinMarker markers = new PinMarker(pinRecordCursor.getString(1),pinRecordCursor.getString(2),
                            pinRecordCursor.getString(3),pinRecordCursor.getString(4));
                    mPinMarkerList.add(markers);
                }while(pinRecordCursor.moveToNext());
                pinRecordCursor.close();
                for  (GLNetTestPinMarker mm : mPinMarkerList) {
                    mMap.addMarker(mm.getMarkerOption());
                }
            }
        }
        catch(Exception e)
        {
            mLogger.printLog("pin", "Exception in MapHandler-->setPinOnMap");
            mLogger.printLog("pin", e.getMessage());
        }
    }

这是PinMarker的代码.....

public class PinMarker {

private LatLng mMallCoordinates = null;
private MarkerOptions mTestPinOptions=null;
private Double mLatitude;
private Double mLongitude;
private GoogleMap googlemap;
private static Logger mLogger = null;

public PinMarker(String testName, String testType, String latitude, String longitude)
{
    mLatitude = Double.parseDouble(latitude);
    mLongitude = Double.parseDouble(longitude);
    mMallCoordinates = new LatLng(mLatitude, mLongitude);
    mTestPinOptions = new MarkerOptions();
    mTestPinOptions.position(mMallCoordinates);
    mTestPinOptions.title(testName);
    mTestPinOptions.snippet( latitude + ", " + latitude);      
    if(testType.equals("Manual"))
        mTestPinOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.mark_red));
    if(mLogger==null)
        mLogger = new Logger();
    mLogger.printLog("pin", "-----------------------GLNetTestPinMarker-----------------------");
    mLogger.printLog("pin", testName+ " : "+ testType +" : "+ latitude+" : "+longitude);

}

public MarkerOptions getMarkerOption()
{
    return mTestPinOptions;

}

}

我在onCreate()方法中执行此操作。

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d("MAP","Coming inside on onCreate()");
    mTestPinRecordHandler = new TestPinRecordHandler(getApplicationContext());
    mLogger = new Logger();
    setContentView(R.layout.activity_map_sample);
    /**Add pin to map */
    setPinOnMap();

    /*********************************************************************************************************/
    try{
        mPlayServiceStatus = checkGooglePlayServicesAvailability();
    }
    catch(Exception e)
    {
        System.out.println("Kindly update the Google Play service");
    }
    String lPreviousZoomLevelString = Config.getSetting(getApplicationContext(), "MAPZOOMLEVEL");
    if(lPreviousZoomLevelString == null || lPreviousZoomLevelString.length() == 0)
    {
        Config.setSetting(getApplicationContext(), "MAPZOOMLEVEL", Float.toString(mPreviousZoomLevel));
    }
    if(mPlayServiceStatus)
    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapView)).getMap();
//      mMap.setMyLocationEnabled(true);
    Log.d("MAP","Coming inside on onCreate()");
    /** Create GPSListener object to handle GPS values */
    mGPSListener = new GPSListener(getApplicationContext());
//      if(Integer.parseInt(Config.getSetting(getApplicationContext(), "KEEPALIVEDURATION"))<=5)
//      {
        try{
        GPSListener.UseLastKnownLocation();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
//      }
    /** Handle the setup button or tab **/
    Button setup = (Button) findViewById(R.id.setup);
    setup.setOnClickListener(new configclicker()); 

    /** Handle the manualtest button or tab **/
    Button mantest = (Button) findViewById(R.id.mantest);
    mantest.setOnClickListener(new manualtestclicker()); 

    /** Handle the home button or tab **/
    Button home = (Button) findViewById(R.id.home);
    home.setOnClickListener(new homeclicker());   

    /** Handle the map button or tab **/
    Button mapView = (Button) findViewById(R.id.maps );
    mapView.setEnabled(false);
    mapView.setPressed(false);        
    if(!isGoogleMapsInstalled())
    {            
        Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Please install Google Maps");
        builder.setCancelable(false);
        builder.setPositiveButton("Install", getGoogleMapsListener());
        AlertDialog dialog = builder.create();
        dialog.show();        
    }
    try{
        if(mPlayServiceStatus){
            mMap.setOnCameraChangeListener(new OnCameraChangeListener (){

                @Override
                public void onCameraChange(CameraPosition lcameraposition) {
                    // TODO Auto-generated method stub
                    if(mPreviousZoomLevel != lcameraposition.zoom && CommandHandler.mLoadingMapFirstTime )
                    {
                        CommandHandler.mLoadingMapFirstTime = false;
                    }
                    else
                    {
                        mPreviousZoomLevel = lcameraposition.zoom;
                    }
                    Config.setSetting(getApplicationContext(), "MAPZOOMLEVEL", Float.toString(mPreviousZoomLevel));
                }

            });
        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
        System.out.println("Exception 1: "+ e.getMessage());
    }
    /** Gray the current selected button or tab i.e about button **/
    Button about = (Button) findViewById(R.id.about);
    about.setOnClickListener(new abouttestclicker());
    /**Set current location in google map*/
    if(mPlayServiceStatus)
        setCurrentLocation();       

    mHandler = new Handler();
    if(mPlayServiceStatus){
        mHandler.removeCallbacks(updateCenterTask);
        mHandler.postDelayed(updateCenterTask, 100);
    }
}

所以我在哪里犯错。我推荐https://developers.google.com/maps/documentation/android/marker

Abhinav辛格·毛里雅

在Google Map的地图版本2中,您只需添加多个标记即可

mGoogleMap.addMarker(new MarkerOptions().position(new LatLng(lat, longitude)).title("Pin title"));

在for循环中输入不同的经/纬度值。其中,mGoogleMap是V2中GoogleMap的对象

请检查您的操作是否正确。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Rails Google Api 在主页中显示地图,点保存在数据库中

多个标记未显示在Google Maps V2中

搜索时如何使用数据库中的 PHP 在 Google 地图中显示多个标记?

使用 Angular2 中的谷歌地图在数据库中插入位置

使用 Vue 的 Google 地图 API 不会显示来自数据库值的标记

Google Map v2:在Google Maps上显示多个位置

远程XML在Google Maps v2上的标记

如何在Google Maps上显示存储在Firebase数据库中的多个标记坐标

Android Maps API v2上的跳转标记

在Google Maps API v2 Android中添加多个标记

标记未显示在我的Google Map API V2(空白Acitivity)中

在数据库中的网页上显示表格

如何在 .NET Core API 中显示保存在数据库中的图像?

Google Map API v2未在设备上显示地图

在静态地图API上显示多个标记

带有Google Map的Laravel未在数据库中显示纬度和经度值的标记

Spring Boot-Google OAuth2,将刷新令牌存储在数据库中

如何使用数据库中的纬度和经度值在Google地图上显示?

显示数据库中已经存在数据的文本

数据未显示在数据库中

我的HTML数据未显示在数据库中

Google Maps Android API v2中带有文字的地图标记

Google android maps api v2始终显示标记标题

Google Maps Android API v2在缩放级别上显示标记

在数据库中的jQuery DataTable中显示图像

在数据库中添加文章标记

为什么片段中仅显示一个Google Maps V2标记?

谷歌地图api显示来自数据库的图像

如何在Android上使用Google Maps API v2很好地管理标记