我正在开发一个在android 2.3设备中成功显示地图和标记的应用程序,但在android 4.3设备中它不会在地图上显示任何标记。我没有收到任何错误。
代码:
GoogleMap _googleMap;
LatLng myPosition;
LocationManager locationManger;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_map_when_login);
_googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.mapId)).getMap();
LocationManager service = (LocationManager)getSystemService(LOCATION_SERVICE);
boolean enableGPS = service.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean enableWiFi= service.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if(!enableGPS || !enableWiFi){
Toast.makeText(ShowMapWhenLoginActivity.this, "GPS signal not found",
Toast.LENGTH_LONG).show();
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
locationManger = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = service.getBestProvider(criteria, true);
service.requestLocationUpdates(provider, 0, 0, this);
if(_googleMap==null){
Toast.makeText(getApplicationContext(), "Google Map Not Available",
Toast.LENGTH_LONG).show();
}
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
//locationManger.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
this);
_googleMap.clear();
ArrayList<HashMap<String, String>> arl = (ArrayList<HashMap<String, String>>)
getIntent().getSerializableExtra("arrayList");
if(location!=null){
double latitude = location.getLatitude();
double langitude = location.getLongitude();
LatLng latlang = new LatLng(latitude, langitude);
myPosition = new LatLng(latitude, langitude);
}
if(arl.size()!=0){
for(int j = 0;j<arl.size();j++){
/* Log.e("SIZE", ""+arl.size());
Log.e(" NEW LAT",arl.get(j).get("lat").toString());
Log.e(" NEW LONG",arl.get(j).get("lng").toString());
Log.e(" NEW ADDRESS",arl.get(j).get("address").toString());
Log.e(" NEW CTIME",arl.get(j).get("ctime").toString());
*/
String lat =arl.get(j).get("lat").toString();
String lng =arl.get(j).get("lng").toString();
if ( !lat.trim().equals("") && !lng.trim().equals("") ) {
double Hlat = Double.parseDouble(lat.trim());
double Hlong= Double.parseDouble(lng.trim());
LatLng dabaseLocations =new LatLng(Hlat, Hlong);
Marker HYD = _googleMap.addMarker(new MarkerOptions()
.position(dabaseLocations)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
.flat(true));
// Show current location with database locations
_googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(myPosition,5));
Marker m=_googleMap.addMarker(new
MarkerOptions().position(myPosition).title("start"));
// HYD.setPosition(new LatLng(5,5));
}
}
}
else{
// Show only Current Location
_googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(myPosition,5));
_googleMap.addMarker(new
MarkerOptions().position(myPosition).title("start"));
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}