(Android)如何在mapview中设置默认gps位置
因此,我有一个应用程序,必须显示一些商店的位置,这取决于你选择哪一家。 具有mapView的页面的XML布局是ViewFlipper的一部分,具有map布局的部分是:(Android)如何在mapview中设置默认gps位置,android,controller,geolocation,gps,android-mapview,Android,Controller,Geolocation,Gps,Android Mapview,因此,我有一个应用程序,必须显示一些商店的位置,这取决于你选择哪一家。 具有mapView的页面的XML布局是ViewFlipper的一部分,具有map布局的部分是: <RelativeLayout android:id="@+id/RelativeLayout3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawa
<RelativeLayout
android:id="@+id/RelativeLayout3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/back2"
android:gravity="left" >
<ImageButton
android:id="@+id/backLocation3"
android:layout_width="72dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:src="@drawable/btn_zuruck2" />
<ImageView
android:id="@+id/imageViewMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/backLocation3"
android:layout_marginTop="14dp"
android:src="@drawable/businesslounge" />
<RelativeLayout
android:id="@+id/mapPlaceHolderLayout"
android:layout_width="300dp"
android:layout_height="200dip"
android:layout_alignLeft="@+id/backLocation3"
android:layout_below="@+id/imageViewMap"
android:layout_marginTop="92dp" >
</RelativeLayout>
<TextView
android:id="@+id/mapLocation"
android:layout_width="240dp"
android:layout_height="40dp"
android:layout_alignLeft="@+id/mapPlaceHolderLayout"
android:layout_below="@+id/imageViewMap"
android:layout_marginTop="47dp"
android:text="@string/maplocation"
android:textSize="25dp"
android:textColor="@color/purple" />
<ImageButton
android:id="@+id/phonereserve"
android:layout_width="220dp"
android:layout_height="36dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="24dp"
android:src="@drawable/rezervephone" />
</RelativeLayout>
xml中的R.id.MapPlaceholder布局不是mapview,因此不能将其强制转换为mapview。该行将导致异常。mapPlaceHolderLayout.addView(onCreateMapView());调用MapHostFragment,它调用LocalActivityManagerFragment,它以某种方式转到LocationMapActivity,它扩展了MapActivity,所以我可以在这里实例化Mapcontroller,一切都正常运行你设置了Google Map API键了吗?是的,地图现在可以工作了,但不知道如何设置中心位置这里有一些很好的地图教程:其中包括设置中心点我设法使其运行,并设置gps位置,所以谢谢,这有点帮助,但我知道我的程序中出现了“无法连接工厂客户端”错误,我不知道为什么,因为它工作得很好,直到我不小心删除了我的调试键。我制作了另一个API密钥,并尝试了调试版本和生产签名版本,但仍然没有成功。好的,但是如何使用mapview?因为我知道mapPlaceHolderLayout是一个布局,它会加载地图。OnCreateMaproview的代码做什么?请发布代码。好的,显然我没有看到这个,但我看不出你在哪里实际添加地图视图到布局中。它不在XML中,我也没有在任何地方的代码中看到它。你需要将地图视图充气并添加到布局中。你能给我解释一下怎么做吗?我在安卓有点呆头呆脑,这几周我学到了很多东西,但仍有很多东西要讲。我在画面中看到的都是那些方块,当地图没有载入谷歌地图时,你会看到这些方块。我让它显示地图,但仍然不知道如何设置地图开始的默认地理位置
public class StandorteFragment extends MapHostFragment {
public String text2;
private RelativeLayout mapPlaceHolderLayout;
public AQuery aQuery;
private MapView myMapView;
private GeoPoint geoPoint;
private MapController mc;
@Override
protected Class<? extends Activity> getActivityClass() {
return LocationMapActivity.class;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.location, container, false);
ViewFlipperStandorte = (ViewFlipper) v.findViewById(R.id.viewFlipperLocation);
geoPoint = new GeoPoint( (int) (48.949997* 1E6), (int) (22.140213 * 1E6));
mapPlaceHolderLayout = (RelativeLayout)v.findViewById(R.id.mapPlaceHolderLayout);
mapPlaceHolderLayout.addView(onCreateMapView());
// myMapView = (MapView) v.findViewById(R.id.mapPlaceHolderLayout);
// mc = myMapView.getController();
// mc.animateTo(geoPoint);
//
public View onCreateMapView() {
Intent intent = new Intent(getActivity(), getActivityClass());
final Window w = getLocalActivityManager().startActivity(ACTIVITY_TAG,
intent);
final View wd = w != null ? w.getDecorView() : null;
if (wd != null) {
ViewParent parent = wd.getParent();
if (parent != null) {
ViewGroup v = (ViewGroup) parent;
v.removeView(wd);
}
wd.setVisibility(View.VISIBLE);
wd.setFocusableInTouchMode(true);
if (wd instanceof ViewGroup) {
((ViewGroup) wd)
.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
}
}
return wd;
}