2

Android googlemap をプログラムで移動する方法を見つける必要があります。マップが機能するようになりましたが、Google ジオコーダー httprequest によって提供された特定の座標にマップをセンタリングする機能を追加する必要があります。Google からの応答から座標を取得しましたが、実際にマップをそのポイントに移動する方法が見つかりませんでした。

私は主に参照アセンブリに問題があります。私は Xamarin C# を使用していますが、すべてのチュートリアルと例は Java にあり、呼び出しはまったく異なり、C# にはないものが必要です。

  • マップ上の目的の場所にマップを移動するにはどうすればよいですか?
  • そして、そのポイントにマーカーを配置するにはどうすればよいですか?

また、回答に必要な参照アセンブリの名前を追加してください。追加/使用するものがわかります。

ありがとうございました

.

関連するコードは次のとおりです。

MapsActivity.cs

public class MapsActivity : FragmentActivity {
    Query q;
    int latE6, lonE6;
    LatLng coordinates;

    protected override void OnCreate(Bundle bundle) 
    {
        base.OnCreate(bundle);
        SetContentView (Resource.Layout.Map);

        EditText sText = FindViewById<EditText> (Resource.Id.et_location);
        Button fButton = FindViewById<Button> (Resource.Id.btn_find);
        fButton.Click += (sender, e) => {
            q = new Query(sText.Text);
            q.CreateQuery();
            var result = q.ResponseFromGoogle.results.Find (item => item.geometry.location.lat.ToString("F") != null);
            sText.Text = result.geometry.location.lat.ToString("F") + " " + result.geometry.location.lat.ToString("F");

            coordinates = new LatLng(result.geometry.location.lat, result.geometry.location.lng);
        };
    }
}

AndroidManifest.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="IgluHarkka2.IgluHarkka2">
<uses-sdk android:minSdkVersion="7" />
<application android:label="@string/app_name">
    <uses-library android:name="com.google.android.maps" />
    <!-- Put your Google Maps V2 API Key here. This key will not work for you.-->
    <!-- See https://developers.google.com/maps/documentation/android/start#obtaining_an_api_key -->
    <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="XXXXXXXXXX" />
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />

Map.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <Button
        android:id="@+id/btn_find"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/str_btn_find"
        android:layout_alignParentRight="true" />
    <EditText
        android:id="@+id/et_location"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="text"
        android:hint="@string/hnt_et_location"
        android:layout_toLeftOf="@id/btn_find" />
</RelativeLayout>
<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment" />

4

1 に答える 1