Java 获取特定位置的地图视图我选择它纬度&;经度
我想在我的活动中放置一张地图,通过选择纬度和经度来显示特定的位置。我尝试了这段代码,但它不起作用。有人能告诉我为什么吗Java 获取特定位置的地图视图我选择它纬度&;经度,java,android,google-maps,google-maps-api-3,Java,Android,Google Maps,Google Maps Api 3,我想在我的活动中放置一张地图,通过选择纬度和经度来显示特定的位置。我尝试了这段代码,但它不起作用。有人能告诉我为什么吗 public class conactus extends Activity{ private GoogleMap map; private LatLng myLoc; double latitude=34.112924; double longitude=35.650288; @SuppressLint("NewApi") p
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();
}
}
}
公共类conactus扩展活动{
私人谷歌地图;
私人车床;
双纬度=34.112924;
双经度=35.650288;
@SuppressLint(“NewApi”)受保护的void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_connectus);
MapFragment fm=(MapFragment)getFragmentManager().findFragmentById(R.id.map);
fm.getMap();
Geocoder Geocoder=新的地理编码器(getBaseContext(),Locale.getDefault());
试一试{
List ad=geoCoder.getFromLocation(纬度,经度,1);
如果(广告大小()>0){
myLoc=新车床(
(int)(ad.get(0.getLatitude()*1E6),
(int)(ad.get(0.getLongitude()*1E6));
map.setMapType(GoogleMap.map\u TYPE\u NORMAL);
CameraUpdate update=CameraUpdateFactory.newLatLngZoom(myLoc,14);
map.animateCamera(更新);
}
}捕获(IOE异常){
e、 printStackTrace();
}
}
}
首先尝试在真实设备上调试,有时gmap不会显示在模拟器中。
还要检查您的map调试密钥是否有效。
此外,如果仍然存在问题,使用指南非常简单。您应该更改
fm.getMap()
tomap=fm.getMap()代码>您遇到了什么错误。请参考此错误,您可以发布stacktrace吗?在映射xmlns:map=“”中为标记片段找到了意外的命名空间前缀“xmlns”