从 JSON 文件解析一个地理点时,我有一个 MapView,drawable 看起来很正常,但是当我解析地图集的所有地理点时,drawable 图标看起来丑陋和变形?什么会导致这个?我也在使用 MapView Ballons Library。MapView 气球
毁容的地图密码
public class ViewAll extends MapActivity
{ static final String KEY_MAPNAME = "name";
static final String KEY_MAPLOCATION = "address";
static final String KEY_MAPLONG = "longitude";
static final String KEY_MAPLAT = "latitude";
static final String KEY_MAPSETMAPSET = "";
TapControlledMapView mapView; // use the custom TapControlledMapView
List<Overlay> mapOverlays;
Drawable drawable;
SimpleItemizedOverlay itemizedOverlay;
;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.maps);
Intent in = getIntent();
String mapset = in.getStringExtra(KEY_MAPSETMAPSET);
mapView = (TapControlledMapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(false);
// dismiss balloon upon single tap of MapView (iOS behavior)
mapView.setOnSingleTapListener(new OnSingleTapListener() {
public boolean onSingleTap(MotionEvent e) {
itemizedOverlay.hideAllBalloons();
return true;
}
});
mapOverlays = mapView.getOverlays();
// first overlay
drawable = getResources().getDrawable(R.drawable.marker2);
itemizedOverlay = new SimpleItemizedOverlay(drawable, mapView);
// set iOS behavior attributes for overlay
itemizedOverlay.setShowClose(false);
itemizedOverlay.setShowDisclosure(true);
itemizedOverlay.setSnapToCenter(false);
try {
JSONObject jOBj;
JSONArray jsonArray;
JSONArray jarray=new JSONArray(mapset);
for(int j=0;j<jarray.length();j++){
jOBj=jarray.getJSONObject(j);
jsonArray = jOBj.getJSONArray("locations");
for(int i=0;i < jsonArray.length();i++){
JSONObject maps = jsonArray.getJSONObject(i);
String.valueOf(i);
String latitude = maps.getString("latitude");
String longitude = maps.getString("longitude");
String name = maps.getString("name");
String address = maps.getString("address");
double lat = Double.parseDouble(latitude);
double lng = Double.parseDouble(longitude);
GeoPoint point = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
OverlayItem overlayItem = new OverlayItem(point, name,
address);
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
// second overlay
if (savedInstanceState == null) {
final MapController mc = mapView.getController();
mc.animateTo(point);
mc.setZoom(2);
} else {
// example restoring focused state of overlays
int focused;
focused = savedInstanceState.getInt("focused_1", -1);
if (focused >= 0) {
itemizedOverlay.setFocus(itemizedOverlay.getItem(focused));
}
}
RadioGroup radGrp = (RadioGroup) findViewById(R.id.map_type);
int checkedRadioButtonID = radGrp.getCheckedRadioButtonId();
radGrp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup arg0, int id) {
switch (id) {
case R.id.maps:
mapView.setSatellite(false);
break;
case R.id.satellite:
mapView.setSatellite(true);
break;
default:
mapView.setSatellite(false);
break;
}
}
}); }
}
}catch(JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
}
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}}
法线贴图密码
public class Maps extends MapActivity
{
static final String KEY_MAPSETMAPSET = "";
static final String KEY_MAPNAME = "name";
static final String KEY_MAPLOCATION = "address";
static final String KEY_MAPLONG = "longitude";
static final String KEY_MAPLAT = "latitude";
TapControlledMapView mapView; // use the custom TapControlledMapView
List<Overlay> mapOverlays;
Drawable drawable;
Drawable drawable2;
SimpleItemizedOverlay itemizedOverlay;
SimpleItemizedOverlay itemizedOverlay2;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.maps);
Intent in = getIntent();
String name = in.getStringExtra(KEY_MAPNAME);
String address = in.getStringExtra(KEY_MAPLOCATION);
String longitude = in.getStringExtra(KEY_MAPLONG);
String latitude = in.getStringExtra(KEY_MAPLAT);
mapView = (TapControlledMapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(false);
// dismiss balloon upon single tap of MapView (iOS behavior)
mapView.setOnSingleTapListener(new OnSingleTapListener() {
public boolean onSingleTap(MotionEvent e) {
itemizedOverlay.hideAllBalloons();
return true;
}
});
mapOverlays = mapView.getOverlays();
// first overlay
drawable = getResources().getDrawable(R.drawable.marker2);
itemizedOverlay = new SimpleItemizedOverlay(drawable, mapView);
// set iOS behavior attributes for overlay
itemizedOverlay.setShowClose(false);
itemizedOverlay.setShowDisclosure(true);
itemizedOverlay.setSnapToCenter(false);
double lat = Double.parseDouble(latitude);
double lng = Double.parseDouble(longitude);
GeoPoint point = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
OverlayItem overlayItem = new OverlayItem(point, name,
address);
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
// second overlay
if (savedInstanceState == null) {
final MapController mc = mapView.getController();
mc.animateTo(point);
mc.setZoom(16);
} else {
// example restoring focused state of overlays
int focused;
focused = savedInstanceState.getInt("focused_1", -1);
if (focused >= 0) {
itemizedOverlay.setFocus(itemizedOverlay.getItem(focused));
}
}
RadioGroup radGrp = (RadioGroup) findViewById(R.id.map_type);
int checkedRadioButtonID = radGrp.getCheckedRadioButtonId();
radGrp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup arg0, int id) {
switch (id) {
case R.id.maps:
mapView.setSatellite(false);
break;
case R.id.satellite:
mapView.setSatellite(true);
break;
default:
mapView.setSatellite(false);
break;
}
}
}); }
@Override
protected boolean isRouteDisplayed() {
return false;
}
@Override
protected void onSaveInstanceState(Bundle outState) {
// example saving focused state of overlays
if (itemizedOverlay.getFocus() != null) outState.putInt("focused_1", itemizedOverlay.getLastFocusedIndex());
super.onSaveInstanceState(outState);
}
}