Google지도 api v2를 사용하여 맞춤형 Android지도를 만들고 있습니다. 나는이 사용자의 현재 location.my 코드에 마커를 넣어 원 :현재 위치에 마커를 추가하는 데 문제가 있습니다.
// Enabling MyLocation in Google Map
getMap().setMyLocationEnabled(true);
// BY THIS YOU CAN CHANGE MAP TYPE
// mGoogleMap.setMapType(mGoogleMap.MAP_TYPE_SATELLITE);
try {
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
// getting GPS status
isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// getting network status
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
// no network provider is enabled
} else {
this.canGetLocation = true;
// First get location from Network Provider
if (isNetworkEnabled) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network");
if (locationManager != null) {
Currentloc = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (Currentloc != null) {
onLocationChanged(Currentloc);
latitude = Currentloc.getLatitude();
longitude = Currentloc.getLongitude();
}
}
}
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled) {
if (Currentloc == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null) {
Currentloc = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (Currentloc != null) {
onLocationChanged(Currentloc);
latitude = Currentloc.getLatitude();
longitude = Currentloc.getLongitude();
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
markerOptions = new MarkerOptions();
// double lat = Currentloc.getLatitude();
// double lng = Currentloc.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
// Setting the position for the marker
markerOptions.position(latLng);
// Setting the title for the marker.
// This will be displayed on taping the marker
markerOptions.title("ADD IMAGE?");
// markerOptions.snippet("ADD IMAGE?");
// Placing a marker on the touched position
getMap().addMarker(markerOptions);
getMap().setOnMarkerClickListener((OnMarkerClickListener) this);
코드를 OnLocationChanged 오류가없는 실행
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
mLatitude = location.getLatitude();
mLongitude = location.getLongitude();
// LatLng latLng = new LatLng(mLatitude, mLongitude);
//markerOptions.notify();
//getMap().addMarker(markerOptions);
getMap().moveCamera(
CameraUpdateFactory.newLatLng(new LatLng(
location.getLatitude(), location.getLongitude())));
getMap().animateCamera(CameraUpdateFactory.zoomTo(12));
}
내 프로그램입니다. 사용자의 현재 위치에 나에게지도에 파란색 포인터를 주어진 그리고 난 수동 (위의 코드 AS) 사용자 curent 위치에 마커를 추가
getMap().setMyLocationEnabled(true);
하지만 내 문제는 누군 데 마커와 블루 포인터에이 라인을입니다 그들은 같은 loc (동일한 위도와 경도)를 설명하기 때문에 같은 위치가됩니다. 그러나 내 코드를 실행하면 출력이이 이미지처럼 보입니다. https://www.dropbox.com/s/argxzb1fnarzie4/Screenshot_2014-11-05-02-43-06.png?dl=0 내 질문에 따르면 내 위치는 동일하지만 왜 그럴 필요가없는 것입니까? 파란색 포인터의 동일한 위치에 마커를 추가하려면 어떻게해야합니까? Thnanks 사전에 내가 노력 할게요
왜 이것을 OnLocationChanged (위치 정보) //getMap().addMarker(markerOptions)에 주석으로 만드세요? –