我一直在尝试在地图上显示 JSON API 的纬度和经度,现在我已经解析了 json 值并使用 android book 创建了逐项叠加。然而,这两件事没有联系,我不确定如何将解析纬度/经度放在地图上。谁能给我一个解决方案
我正在尝试将值解析为数组并将它们显示在地图上。
我怎样才能做到这一点?
任何解决方案将不胜感激。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
// mapView.setStreetView(true);
// mapView.isStreetView();
// mapView.isSatellite();
JSONArray properties = null;
JSONParser jParser = new JSONParser();
JSONObject json = jParser.getJSONFromUrl(url);
try {
// Getting Array of Contacts
properties = json.getJSONArray(TAG_PROPERTY);
// looping through All Contacts
for (int i = 0; i < properties.length(); i++) {
JSONObject c =
properties.getJSONObject(i);
String lat = c.getString(TAG_LATITUDE);
String longi = c.getString(TAG_LONGITUDE);
System.out.println(lat);
}
} catch (Exception e) {
}//getting JSOn values
Drawable marker=getResources().getDrawable(R.drawable.mapmarker);
marker.setBounds((int)(-marker.getIntrinsicWidth()/2),
-marker.getIntrinsicHeight(),
(int) (marker.getIntrinsicWidth()/2),
0);
InterestingLocations funPlaces = new InterestingLocations(marker);
mapView.getOverlays().add(funPlaces);
GeoPoint pt = funPlaces.getCenterPt();
double latSpan = funPlaces.getLatSpanE6();
double lonSpan = funPlaces.getLonSpanE6();
Log.v("Overlays", "Lat span is " + latSpan);
Log.v("Overlays", "Lon span is " + lonSpan);
MapController mc = mapView.getController();
mc.setCenter(pt);
mc.zoomToSpan((int)(latSpan*1.5), (int)(lonSpan*1.5));
}
@Override
protected boolean isLocationDisplayed() {
return false;
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
class InterestingLocations extends ItemizedOverlay {
private ArrayList<OverlayItem> locations = new ArrayList<OverlayItem>();
private GeoPoint center = null;
我需要使用对象数组替换以下代码
public InterestingLocations(Drawable marker)
{
super(marker);
// create locations of interest
GeoPoint Maddox = new
GeoPoint((int)(51.513292002080306*1000000),(int)(-0.1420965932139256*1000000));
GeoPoint WoburnPlace = new
GeoPoint((int)(51.52457273349151*1000000),(int)(-0.12765430497584865*1000000));
GeoPoint Capstansquare = new
GeoPoint((int)(51.49858590609855*1000000),(int)(-0.007696115597470304*1000000));
GeoPoint Devonshire = new
GeoPoint((int)(51.52222533547292*1000000),(int)(-0.1440394063396748*1000000));
GeoPoint Bolsover = new
GeoPoint((int)(51.52266783118477*1000000),(int)(-0.14358896505772278*1000000));
GeoPoint Haymarket = new
GeoPoint((int)(51.51000027761305*1000000),(int)(-0.13300746016819762*1000000));
locations.add(new OverlayItem(Haymarket,
"Seven Seas Lagoon", "Seven Seas Lagoon"));
locations.add(new OverlayItem(Bolsover,
"Seven Seas Lagoon", "Seven Seas Lagoon"));
locations.add(new OverlayItem(Devonshire,
"Seven Seas Lagoon", "Seven Seas Lagoon"));
locations.add(new OverlayItem(Capstansquare,
"Seven Seas Lagoon", "Seven Seas Lagoon"));
locations.add(new OverlayItem(WoburnPlace,
"Seven Seas Lagoon", "Seven Seas Lagoon"));
locations.add(new OverlayItem(Maddox,
"Magic Kingdom", "Magic Kingdom"));
populate();
}
// We added this method to find the middle point of the cluster
// Start each edge on its opposite side and move across with each point.
// The top of the world is +90, the bottom -90,
// the west edge is -180, the east +180
public GeoPoint getCenterPt() {
if(center == null) {
int northEdge = -90000000; // i.e., -90E6 microdegrees
int southEdge = 90000000;
int eastEdge = -180000000;
int westEdge = 180000000;
Iterator<OverlayItem> iter = locations.iterator();
while(iter.hasNext()) {
GeoPoint pt = iter.next().getPoint();
if(pt.getLatitudeE6() > northEdge) northEdge = pt.getLatitudeE6();
if(pt.getLatitudeE6() < southEdge) southEdge = pt.getLatitudeE6();
if(pt.getLongitudeE6() > eastEdge) eastEdge = pt.getLongitudeE6();
if(pt.getLongitudeE6() < westEdge) westEdge = pt.getLongitudeE6();
}
center = new GeoPoint((int)((northEdge + southEdge)/2),
(int)((westEdge + eastEdge)/2));
}
return center;
}
@Override
public void draw(Canvas canvas, MapView mapview, boolean shadow) {
// Here is where we can eliminate shadows by setting to false
super.draw(canvas, mapview, shadow);
}
@Override
protected OverlayItem createItem(int i) {
return locations.get(i);
}
@Override
public int size() {
return locations.size();
}
}
我需要实现这样的目标