Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
370 views
in Technique[技术] by (71.8m points)

android - how can get the information for place on google map?

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

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You want to show more data in marker info window so you need to put some data in marker when it create .you should make some new things like that: 1. Firstly create a hash map to put the value.

 HashMap<String, String> map = new HashMap<>();
        map.put("userId", userId);
        map.put("userName", name);
        if(profileImage.equalsIgnoreCase(""))
        map.put("imageUrl", null);
        else
            map.put("imageUrl", profileImage);
        map.put("primaryInstrumentName", primary_Instrument_name);

        googleMap.addMarker(new MarkerOptions()
                .position(new LatLng(Double.valueOf(latitude), Double.valueOf(lonnitude))).snippet(String.valueOf(map))
                .icon(R.drawable.marker);

when u set listner on google map info window its return the marker object get marker.getsnippet which return the hashmap type string convert it in single key value according to this code:

 private Map<String, String> getMarkerDetails(Marker marker) {
        String name2 = marker.getSnippet();
        System.out.println("name  "+name2);

        name2 = name2.substring(1, name2.length() - 1);
        String[] keyValuePairs = name2.split(",");
        Map<String, String> map = new HashMap<>();

        for (String pair : keyValuePairs) {
            String[] entry = pair.split("=");
            System.out.println("name map is "+entry[0]+" "+entry[1]);
            map.put(entry[0].trim(), entry[1].trim());
        }
        return map;
    }

this would help to get back key value from string hashmap using this like:

getMarkerDetails(marker).get("userName").toString();

this will return to marker "username" data , use wherever need.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...