我正在开发xamarin中的android地图应用程序。我做了所有的事情
创建API密钥 生成SH1 KEY 给予所有必要的许可。但我仍然在地图上得到灰色区域。我从2天开始面对这个问题。文章都没有帮助我。
这是我的Manifest.XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="Param.Param">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
<application android:label="Param" android:icon="@drawable/icon">
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyCy_xogJYFs3nita-S8DHXnLE83z-B_FUw" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
</application>
<uses-library android:name="com.google.android.maps" />
<!-- Google Maps for Android v2 requires OpenGL ES v2 -->
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<!-- We need to be able to download map tiles and access Google Play Services-->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Allow the application to access Google web-based services. -->
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- Google Maps for Android v2 will cache map tiles on external storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Google Maps for Android v2 needs this permission so that it may check the connection state as it must download data -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Permission to receive remote notifications from Google Play Services -->
<!-- Notice here that we have the package name of our application as a prefix on the permissions. -->
<uses-permission android:name="param.param.permission.MAPS_RECEIVE" />
<permission android:name="param.param.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
<!-- These are optional, but recommended. They will allow Maps to use the My Location provider. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
这是我的代码
namespace P
{
[Activity (Label = "map")]
public class map : Android.GoogleMaps.MapActivity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView (Resource.Layout.Map);
// Create your application here
Button takeMeThere = FindViewById<Button> (Resource.Id.buttonTake);
takeMeThere.Click += delegate {
Toast.MakeText(this,"RR",ToastLength.Long).Show();
};
////
MapFragment mapFrag = (MapFragment) FragmentManager.FindFragmentById(Resource.Id.map);
GoogleMap map = mapFrag.Map;
if (map != null) {
try{
MarkerOptions markerOpt1 = new MarkerOptions();
markerOpt1.SetPosition(new LatLng(50.379444, 2.773611));
markerOpt1.SetTitle("Vimy Ridge");
map.AddMarker(markerOpt1);
map.MapType = GoogleMap.MapTypeNormal;
markerOpt1.InvokeIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.pin_base));
map.UiSettings.ZoomControlsEnabled = false;
//map.UiSettings.CompassEnabled = true;
//LatLng location = new LatLng(18.489057,73.924345);
//CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
// builder.Target(location);
//builder.Zoom(18);
// builder.Bearing(155);
// builder.Tilt(65);
// CameraPosition cameraPosition = builder.Build();
// CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);
// map.MoveCamera(cameraUpdate);
}
catch(Exception e){Toast.MakeText (this,e+"",ToastLength.Long).Show();}
}
}
protected override bool IsRouteDisplayed {
get {
return false;
}
}
}
}
这是我的布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="84.0dp"
android:layout_height="40.0dp"
android:id="@+id/buttonback"
android:textColor="#ffada8a8"
android:text="Back"
android:drawableLeft="@drawable/Back_icon"
android:background="#000000"
android:drawablePadding="-20dp"
android:layout_marginLeft="10dp" />
<TextView
android:text="Map"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="112.0dp"
android:layout_height="40.0dp"
android:layout_toRightOf="@id/buttonback"
android:id="@+id/textViewMap"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textColor="#ffffffff" />
<fragment
android:id="@+id/map"
android:layout_marginTop="40dp"
android:layout_width="match_parent"
android:layout_height="295.7dp"
android:name="com.google.android.gms.maps.MapFragment" />
<View
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_below="@id/map"
android:id="@+id/view1"
android:layout_alignParentBottom="true"
android:layout_marginBottom="75dp"
android:background="#2F2E2C" />
<ImageView
android:src="@drawable/Address_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/map"
android:id="@+id/imageView1"
android:layout_alignParentBottom="true"
android:layout_marginBottom="90dp"
android:layout_marginLeft="25dp" />
<TextView
android:text="Address"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/map"
android:id="@+id/textViewaddress"
android:layout_alignParentBottom="true"
android:layout_marginLeft="50dp"
android:layout_marginBottom="85dp" />
<Button
android:text="Take me there"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_below="@id/map"
android:id="@+id/buttonTake"
style="@style/DefaultButton"
android:layout_alignParentBottom="true"
android:layout_marginBottom="7dp"
android:textColor="#ffffffff" />
我仍然在地图上得到灰色区域。 任何人都可以告诉我我在哪里做错了。
答案 0 :(得分:0)
我认为在Google API控制台中尝试在服务标签中启用Google地图v2
答案 1 :(得分:0)
Add this permission into your manifest
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
And use support fragment
GoogleMap googleMap = ((SupportMapFragment) (getSupportFragmentManager()
.findFragmentById(R.id.map))).getMap();
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);