내 앱에서 Google지도를 사용하고 있습니다. lat-long 및 테스트 유형을 데이터베이스에 저장합니다. 데이터베이스에서 해당 값을 검색하고 Google지도에서 마커로 표시하고 있습니다. 테스트 유형에 대해 두 개의 서로 다른 이미지를 사용하고 있습니다. 테스트 유형이 수동이면, 테스트 유형이 자동이면 파란색 이미지를 사용 중이면 Red 이미지를 사용하고 있습니다. 여기 Google지도에서 마커 업데이트
구글지도public void setPinOnMap(){
try{
Cursor pinRecordCursor = mTestPinRecordHandler.getPinFromDatabase();
mPinMarkerList = new ArrayList<TestPinMarker>();
if(pinRecordCursor != null && pinRecordCursor.moveToFirst())
{
do
{//String testName, String testType, String latitude, String longitude
TestPinMarker markers = new TestPinMarker(pinRecordCursor.getString(1),pinRecordCursor.getString(2),
pinRecordCursor.getString(3),pinRecordCursor.getString(4));
mPinMarkerList.add(markers);
}while(pinRecordCursor.moveToNext());
pinRecordCursor.close();
for (TestPinMarker mm : mPinMarkerList) {
mMap.addMarker(mm.getMarkerOption());
}
Thread.sleep(300);
}
}
catch(Exception e)
{
mLogger.printLog("pin", "Exception in MapHandler-->setPinOnMap");
mLogger.printLog("pin", e.getMessage());
}
}
나는()에서 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);
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()");
/**Add pin to map */
setPinOnMap();
mHandler = new Handler();
if(mPlayServiceStatus){
mHandler.removeCallbacks(updateCenterTask);
mHandler.postDelayed(updateCenterTask, 100);
처리기
를 사용하고 값마다를 업데이트를에 가치와 보여주는 검색 내 코드입니다 이것은 내 처리기 코드입니다private Runnable updateCenterTask = new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
try{
if(mMap==null)
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapView)).getMap();
try{
GPSListener.UseLastKnownLocation();
}
catch(Exception e)
{
e.printStackTrace();
}
Log.d("MAP","coming inside map update task");
setPinOnMap();
mCurrentLattitude = mGPSListener.GetLatitudeRaw();
mCurrentLongitude = mGPSListener.GetLongitudeRaw();
Log.d("MAP","lat-lang values: "+mCurrentLattitude +" : "+mCurrentLongitude);
LatLng coordinates = new LatLng(mCurrentLattitude, mCurrentLongitude);
CameraUpdate center= CameraUpdateFactory.newLatLng(coordinates);
mMap.moveCamera(center);
String lPreviousZoomLevelString = Config.getSetting(getApplicationContext(), "MAPZOOMLEVEL");
mPreviousZoomLevel = Float.parseFloat(lPreviousZoomLevelString);
Log.d("MAP","mPreviousZoomLevel value: "+ mPreviousZoomLevel);
CameraUpdate zoom=CameraUpdateFactory.zoomTo(mPreviousZoomLevel);
mMap.animateCamera(zoom);
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
/** Thread is called after a delay period **/
mHandler.postDelayed(updateCenterTask, 5000);
}
}};
나는 마커가 유일한 문제는 내가 perfo rm 테스트는 데이터베이스에서 업데이트 될 때마다 매시간 MapActivity 값으로 업데이트됩니다. MapActivity에서 동일한 프로세스를 수행하는 경우. 이전 마커 이미지 (빨간색)를 새 마커 (파란색)로 업데이트하지 않습니다.
수동 테스트를 수행했습니다. MapActivity로 와서 빨간색 핀을 표시합니다. 어느 쪽이야. 내가 MapActivity에서 자동 테스트를 수행하면 빨간색 핀을 파란색 핀으로 업데이트해야하지만 핀을 클릭하면 두 핀이 하나씩 차례로 클릭됩니다. 하지만 다른 활동으로 전환하고지도 활동으로 돌아 오면 파란색으로 만 표시됩니다.
예 답변을 이미 보내 주신 데 대해 고맙겠습니다. :) – CodingRat