我想在我的活动中放置一张地图,通过选择纬度和经度来显示特定位置我尝试了这段代码,但它不起作用谁能告诉我为什么???
public class conactus extends Activity{
private GoogleMap map;
private LatLng myLoc;
double latitude=34.112924;
double longitude=35.650288;
@SuppressLint("NewApi") protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_connectus);
MapFragment fm = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
fm.getMap();
Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
try {
List<Address> ad = geoCoder.getFromLocation(latitude, longitude,1);
if (ad.size() > 0) {
myLoc = new LatLng(
(int) (ad.get(0).getLatitude() * 1E6),
(int) (ad.get(0).getLongitude() * 1E6));
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(myLoc, 14);
map.animateCamera(update);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}