如果我的 json 的格式如下所示,则带有地址和纬度/经度的商店
[{"StoreId":"50","StoreTitle":"Pocket
Docket","StoreLogo":"","StoreTradingName":"Pocket
Docket","StoreWebsite":"http:\/
\/pocketdocket.com.au","Address":{"Address1":"367
","Address2":"George
St.","City":"Sydney","State":"NSW","ZipCode":"2000","Longitude"
:"151.2284339","Latitude":"-
33.5487607","AreaCode":"2000","Phone":"0280839400"},
和我要显示的mapactivity类如下
public class MapActivity extends com.google.android.maps.MapActivity {
MapView mapView;
private LocationManager mylocmng;
private LocationListener myloclist;
private MapController mympctrl;
private void CenterLocation(GeoPoint centrGeopt){
mympctrl.animateTo(centrGeopt);
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
};
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
mapView=(MapView)findViewById(R.id.mv);
//mapView.setSatellite(true);
mapView.setStreetView(true);
mapView.setBuiltInZoomControls(true);
mympctrl = mapView.getController();
mympctrl.setZoom(8);
mylocmng=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
myloclist=new MyLocationListener();
mylocmng.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,myloclist);
Drawable marker=getResources().getDrawable(android.R.drawable.star_big_on);
int markerWidth = marker.getIntrinsicWidth();
int markerHeight = marker.getIntrinsicHeight();
marker.setBounds(0, markerHeight, markerWidth, 0);
LocationOverlay myItemizedOverlay = new LocationOverlay(marker);
mapView.getOverlays().add(myItemizedOverlay);
/* GeoPoint myPoint1 = new GeoPoint(0*1000000, 0*1000000);
myItemizedOverlay.addItem(myPoint1, "myPoint1", "myPoint1");
GeoPoint myPoint2 = new GeoPoint(50*1000000, 50*1000000);
myItemizedOverlay.addItem(myPoint2, "myPoint2", "myPoint2");
//Get the current location in start-up
GeoPoint initGeoPoint = new GeoPoint(
(int)(mylocmng.getLastKnownLocation(
LocationManager.GPS_PROVIDER)
.getLatitude()*1000000),
(int)(mylocmng.getLastKnownLocation(
LocationManager.GPS_PROVIDER)
.getLongitude()*1000000));
CenterLocation(initGeoPoint);*/
ImageButton bcknrby=(ImageButton)findViewById(R.id.nearbybuttn);
bcknrby.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myint = new Intent(MapActivity.this,NearBy.class);
startActivity(myint);
}
});
}
private class MyLocationListener implements LocationListener{
@Override
public void onLocationChanged(Location argLocation) {
// TODO Auto-generated method stub
Drawable marker=getResources().getDrawable(android.R.drawable.star_big_on);
int markerWidth = marker.getIntrinsicWidth();
int markerHeight = marker.getIntrinsicHeight();
marker.setBounds(0, markerHeight, markerWidth, 0);
LocationOverlay myItemizedOverlay = new LocationOverlay(marker);
mapView.getOverlays().add(myItemizedOverlay);
GeoPoint myGeoPoint = new GeoPoint(
(int)(argLocation.getLatitude()*1000000),
(int)(argLocation.getLongitude()*1000000));
myItemizedOverlay.addItem(myGeoPoint,"myPoint1", "myPoint2");
CenterLocation(myGeoPoint);
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
Toast.makeText( getApplicationContext(), "Gps Disabled", Toast.LENGTH_LONG ).show();
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
Toast.makeText( getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT ).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
如何将坐标从 json 加载到地图视图??????任何帮助将不胜感激。
这是我的解析代码
try{JSONArray myID=j2.getJSONArray("stores");
for(int i=0;i<myID.length();i++){
Log.v("state","json address being read");
JSONObject j3= myID.getJSONObject(i);
String name = j3.getString("Address");
Log.v("Address",name);