Android 数据库与MapView总结
2010-11-05 00:54:34 来源:WEB开发网allRestaurantCal.add(c.getString(3));
}
if(allRestaurantID.size()>0)
{
Random generator = new Random();
int intThrowIndex = generator.nextInt(allRestaurantID.size());
mTextView01.setText
(
allRestaurantName.get(intThrowIndex)+" "+
allRestaurantAddress.get(intThrowIndex)+" "+
allRestaurantCal.get(intThrowIndex)+
getResources().getText(R.string.str_cal)
);
/* 以地址查询地理坐标 */
GeoPoint gp =
getGeoByAddress(allRestaurantAddress.get(intThrowIndex));
if(gp==null)
{
/* 地址无法反查为GeoPoint时 */
mMapView01.setVisibility(MapView.GONE);
}
else
{
/* 更新MapView地图 */
mMapView01.setVisibility(MapView.VISIBLE);
showImageOverlay(gp);
refreshMapViewByGeoPoint
(
getGeoByAddress(allRestaurantAddress.get(intThrowIndex)),
mMapView01, intZoomLevel, true
);
}
}
else
{
/* 数据库无记录 */
}
}
private GeoPoint getGeoByAddress(String strSearchAddress)
{
GeoPoint gp = null;
try
{
if(strSearchAddress!="")
{
Geocoder mGeocoder01 =
new Geocoder(EX10_06_04.this, Locale.getDefault());
List
lstAddress =
mGeocoder01.getFromLocationName(strSearchAddress, 1);
if (!lstAddress.isEmpty())
{
Address adsLocation = lstAddress.get(0);
/* 1E6 = 1000000*/
double geoLatitude = adsLocation.getLatitude()*1E6;
double geoLongitude = adsLocation.getLongitude()*1E6;
gp = new GeoPoint((int) geoLatitude, (int) geoLongitude);
}
更多精彩
赞助商链接