如何获取Google地图上的地点信息? [英] how can get the information for place on google map?

查看:97
本文介绍了如何获取Google地图上的地点信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在搜索餐厅或某个地方时使用Google的信息

I want to use information from Google when I search restaurant or some place

我试图在单击Google Maps中的标记时启动活动

i tried to make start an activity when the marker in Google Maps is clicked

因此请使用onMarkerClick,但它仅包含我需要的名称,地址,地点ID

so use the onMarkerClick but it have only name, address, place ID what i need

@Override
public boolean onMarkerClick(Marker marker) {
    Id = marker.getId();

    String Title = marker.getTitle();
    String Address = marker.getSnippet();

    switch(databaseCheck){
        case 1:
            Intent intent = new Intent(mActivity, PopupGrid.class);
            intent.putExtra("Title" , Title);
            intent.putExtra("Address", Address);
            getActivity().startActivity(intent);
            break;
        case 2:
            Intent intent2 = new Intent(mActivity, Nodatabase.class);
            intent2.putExtra("Title" , Title);
            intent2.putExtra("Address", Address);
            getActivity().startActivity(intent2);
            break;
    }

    return true;
}

如何获取其他信息,例如电话号码,等级和该地点的照片?

how get other information like phone number, rating and Photo of that location?

推荐答案

尝试使用此完整的自定义标记示例.

Try this full example of custom marker.

地图活动:

public void onMapReady(GoogleMap googleMap) { 
mMap.clear();
LinearLayout tv2;
tv2 = (LinearLayout)MapsActivity.this.getLayoutInflater().inflate(R.layout.marker_dialog, 
null, false);
tv2.measure(View.MeasureSpec.makeMeasureSpec(0, 
View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, 
View.MeasureSpec.UNSPECIFIED));
tv2.layout(0, 0, tv2.getMeasuredWidth(), tv2.getMeasuredHeight());
tv2.setDrawingCacheEnabled(true);
tv2.buildDrawingCache();
Bitmap bm2 = tv2.getDrawingCache();
icon2 = BitmapDescriptorFactory.fromBitmap(bm2);
BitmapDescriptorFactory.fromResource(R.drawable.ic_markericon);

HashMap<Marker, JSONObject> stopsMarkersInfo = new HashMap<>();
JSONObject ObjectForMarker;
for (int i = 0; i < YourData.length(); i++) 
{//YourData is JSONArray
  LatLng coordinate = new LatLng(Latitude, Longitude);
  ObjectForMarker = YourData.getJSONObject(i);
  MarkerOptions markerOptions = new 
  MarkerOptions().position(coordinate).icon(Youricon);
  Marker marker = mMap.addMarker(markerOptions);
  stopsMarkersInfo.put(marker, ObjectForMarker); 
}
 googleMap.setInfoWindowAdapter(new StopsInfoWindow(stopsMarkersInfo, getApplicationContext()));
     }

自定义适配器类:

  import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.widget.TextView;
  import com.google.android.gms.maps.GoogleMap;
  import com.google.android.gms.maps.model.Marker;
  import org.json.JSONException;
  import org.json.JSONObject;
  import java.util.HashMap;
  public class StopsInfoWindow implements GoogleMap.InfoWindowAdapter {

private HashMap<Marker, JSONObject> stopsMarkersInfo;
private View view;
Context context;

public StopsInfoWindow(HashMap<Marker, JSONObject> stopsMarkersInfo, Context context) {
    this.stopsMarkersInfo = stopsMarkersInfo;
    this.context = context;
}


@Override
public View getInfoContents(Marker marker) {
    return null;
}

@Override
public View getInfoWindow(final Marker marker) {
    JSONObject stop = stopsMarkersInfo.get(marker);
    if (stop != null) {
        LayoutInflater inflater = (LayoutInflater) context.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        view = inflater.inflate(R.layout.item_stop_marker_info, null);

        TextView iD = (TextView) view.findViewById(R.id.iD);
        TextView Amount = (TextView) view.findViewById(R.id.Amount);
        TextView Date = (TextView) view.findViewById(R.id.Date);



        for (int i = 0; i < stopsMarkersInfo.size(); i++) {

         }

        try {
            iD.setText(stop.getString("iD"));
            Amount.setText(stop.getString("Amount"));
            Date.setText(stop.getString("Date"));


        } catch (JSONException e) {
            e.printStackTrace();
        }


    }
    return view;
  }
  }

marker_dialog.xml:

  <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/myMarker"
   android:layout_width="100dp"
   android:layout_height="wrap_content"
   android:background="@android:color/transparent"
   android:orientation="vertical">
   <ImageView
    android:layout_width="50dp"
    android:layout_height="60dp"
    android:layout_gravity="center_horizontal"
    android:src="@drawable/ic_markericon" />
  </LinearLayout>

item_stop_marker_info.xml: 在标记中声明您想要的所有选项

item_stop_marker_info.xml : Declare all the options you want in your marker

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="@drawable/roundlayout">

  <TextView
    android:id="@+id/iD"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_toRightOf="@+id/MName"
    android:text="iD"
    android:textColor="@color/background"
    android:textSize="13dp" />

<TextView
    android:layout_marginRight="10dp"
    android:id="@+id/Amount"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Amount"
    android:textColor="@color/background"
    android:textSize="13dp" />
  </RelativeLayout>

这篇关于如何获取Google地图上的地点信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆