0

I want to implement several things:

  1. when the activity creates the google maps will show the estimated location based on wifi...
    how can I implement it?

  2. I want to get the name of the location that user touch on google maps...
    I read that I can implement it with the method, however with this method I can only get the latitude and longitude on the place that the user touched:

    @Override
    public void onMapClick(LatLng point) {
        // TODO Auto-generated method stub
    }
    
  3. I want to enable the user to search place in google maps, is there any method to implement it?

This is my activity till now:

import java.lang.ref.WeakReference;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMarkerDragListener;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import android.view.ViewParent;
import android.widget.ImageView;
import android.widget.Toast;

public class itemSaleActivity extends FragmentActivity  {


    private static Context app;
    private static GoogleMap map;
    static final LatLng HAMBURG = new LatLng(53.558, 9.927);
    private static final int LOAD_COORD = 0;
    private ImageView pic;
    private LocationHandler mHandler;

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        // Set View to register.xml
        setContentView(R.layout.itemsale);

        app = getApplicationContext();
        Bundle extras = getIntent().getExtras();
        byte[] byteArray = extras.getByteArray("picture");
        Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);

        pic = (ImageView) findViewById(R.id.itemImage);
        pic.setImageBitmap(bmp);

        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
        //Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG).title("Hamburg"));
        mHandler = new LocationHandler(this); 

        OnMarkerDragListener markerDragListener = new OnMarkerDragListener() {

            @Override
            public void onMarkerDragStart(Marker marker) {
                // Called when the marker drag is started

            }

            @Override
            public void onMarkerDragEnd(Marker marker) {
                // Called when the marker is dropped down.
                double[] coords = null;
                coords[0] = marker.getPosition().latitude;
                coords[1] = marker.getPosition().longitude;
                RestoreUIwithSavedLocation(coords);
                Toast.makeText(getApplicationContext(),"Pin Dropped at: " + coords[0] + ", " + coords[1]+marker.getTitle() , Toast.LENGTH_LONG).show();

            }

            @Override
            public void onMarkerDrag(Marker marker) {

            }
        };

        map.setOnMarkerDragListener(markerDragListener);

        View titleView = getWindow().findViewById(android.R.id.title);
        if (titleView != null) {
            ViewParent parent = titleView.getParent();
            if (parent != null && (parent instanceof View)) {
             View parentView = (View)parent;
             parentView.setVisibility(View.GONE);
            }
        }

     // You can also assign the title programmatically by passing a
     // CharSequence or resource id.
    }

    private void RestoreUIwithSavedLocation(double[] coordsArray) {
        Message.obtain(mHandler, LOAD_COORD, coordsArray).sendToTarget();
    }

    static class LocationHandler extends Handler {
        WeakReference<Activity> mActivity;

        public LocationHandler(Activity activity) {
            mActivity = new WeakReference<Activity>(activity);
        }

        public void handleMessage(Message msg) {
            Activity contextActivity = mActivity.get();
            switch ((int)msg.what) {

            case LOAD_COORD:
                map.clear();
                double[] coordArray = (double[])msg.obj;
                Marker marker = map.addMarker(new MarkerOptions().position(new LatLng(coordArray[0], coordArray[1])));
                map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(coordArray[0], coordArray[1]), 18));
                map.animateCamera(CameraUpdateFactory.zoomTo(18), 2000, null);
                marker.setDraggable(true);
                String s = Double.toString(coordArray[0]) + ", " + Double.toString(coordArray[1]);              
                Toast.makeText(app,"in the case"+s , Toast.LENGTH_LONG).show();
                break;

            }
        }
    }
}

and this is my xml file till now:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/itemImage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:src="@drawable/logo" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="400dp"
        android:layout_marginTop="10dp"
        android:layout_weight="66496.79"
        android:orientation="horizontal" >

        <fragment
            android:id="@+id/map"
            class="com.google.android.gms.maps.MapFragment"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginRight="150dp" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="170dp"
            android:orientation="vertical" >

            <Button
            android:id="@+id/messageBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:text="fffff" />

            <Button
                android:id="@+id/call"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:text="ffff" />

        <Button
            android:id="@+id/sms"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignRight="@+id/button1"
            android:layout_centerVertical="true"
            android:text="ffff" />
        <Button
            android:id="@+id/email"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignRight="@+id/button1"
            android:layout_centerVertical="true"
            android:text="fffff" />

        <Button
            android:id="@+id/navigate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/button1"
            android:layout_alignParentEnd="false"
            android:layout_alignParentStart="false"
            android:layout_below="@+id/button1"
            android:layout_marginTop="14dp"
            android:text="ffffffffff" />
        </LinearLayout>
    </RelativeLayout>
</LinearLayout>
4

1 に答える 1

0
  1. これは、マップ コンポーネントによって自動的に管理されます。重要:アクティビティ/フラグメントの onPauseを呼び出すことを忘れないでください。GoogleMap.setMyLocationEnabled(true);
    GoogleMap.setMyLocationEnabled(false)

  2. GoogleMap.setOnMyLocationChangeListenerユーザーの位置が変わるたびに呼び出されるハンドラーを追加するために使用できます。

  3. を使用Geocoderしてリバース ジオコーディングを実行できますが、結果を取得するにはバックエンドが必要になります。Google Play Serviceライブラリがバックエンドを提供しているのかもしれませんが、私はこの機能を使用したことがないのでわかりません


タッチした場所の名前を検索するには (未テスト) :

MyActivity extends Activity implements OnMapClickListener {

    Geocoder geocoder;

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        geocoder = new Geocoder(this);
    }

    @Override
    public void onMapClick(LatLng point) {
         List<Address> addresses = geocoder.getFromLocation(point.latitude, point.longitude, 1);

         if (adresses.length > 0) {
             Address address = addresses.get(0);
             Toast.makeText(this, address.getFeatureName(), Toast.LENGTH_SHORT).show();
         }
         else {
             Toast.makeText(this, "Not found!", Toast.LENGTH_SHORT).show();
         }
    }
于 2013-03-29T13:29:34.830 に答える