首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在地图视图上显示地址

问在地图视图上显示地址
EN

Stack Overflow用户
提问于 2014-08-02 15:28:52
回答 1查看 890关注 0票数 0

我有两节课

contact片段从联系人列表中获取地址。

ContactDetailFragment.java

代码语言:javascript
复制
 public class ContactDetailFragment extends Fragment implements 
            LoaderManager.LoaderCallbacks<Cursor> {
.
.
.
    @Override
        public void onLoadFinished(Loader<Cursor> loader, Cursor data) {

            // If this fragment was cleared while the query was running
            // eg. from from a call like setContact(uri) then don't do
            // anything.
            if (mContactUri == null) {
                return;
            }

            switch (loader.getId()) {
                case ContactDetailQuery.QUERY_ID:
                    // Moves to the first row in the Cursor
                    if (data.moveToFirst()) {
                        // For the contact details query, fetches the contact display name.
                        // ContactDetailQuery.DISPLAY_NAME maps to the appropriate display
                        // name field based on OS version.
                        final String contactName = data.getString(ContactDetailQuery.DISPLAY_NAME);
                        if (mIsTwoPaneLayout && mContactName != null) {
                            // In the two pane layout, there is a dedicated TextView
                            // that holds the contact name.
                            mContactName.setText(contactName);
                        } else {
                            // In the single pane layout, sets the activity title
                            // to the contact name. On HC+ this will be set as
                            // the ActionBar title text.
                            getActivity().setTitle(contactName);
                        }
                    }
                    break;
                case ContactAddressQuery.QUERY_ID:
                    // This query loads the contact address details. More than
                    // one contact address is possible, so move each one to a
                    // LinearLayout in a Scrollview so multiple addresses can
                    // be scrolled by the user.

                    // Each LinearLayout has the same LayoutParams so this can
                    // be created once and used for each address.
                    final LinearLayout.LayoutParams layoutParams =
                            new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                    ViewGroup.LayoutParams.WRAP_CONTENT);

                    // Clears out the details layout first in case the details
                    // layout has addresses from a previous data load still
                    // added as children.
                    mDetailsLayout.removeAllViews();

                    // Loops through all the rows in the Cursor
                    if (data.moveToFirst()) {
                        do {
                            // Builds the address layout
                            final LinearLayout layout = buildAddressLayout(
                                    data.getInt(ContactAddressQuery.TYPE),
                                    data.getString(ContactAddressQuery.LABEL),
                                    data.getString(ContactAddressQuery.ADDRESS));
                            // Adds the new address layout to the details layout
                            mDetailsLayout.addView(layout, layoutParams);
                        } while (data.moveToNext());
                    } else {
                        // If nothing found, adds an empty address layout
                        mDetailsLayout.addView(buildEmptyAddressLayout(), layoutParams);
                    }
                    break;
            }
        }

MainActivity在地图上显示地址

MainActivity.java

代码语言:javascript
复制
public class MainActivity extends FragmentActivity  implements LocationListener {
.
.
.
private void setUpMap() {

        Geocoder geocoder = new Geocoder(this, Locale.US);

        String staddress = "<address goes here>";

        try{
         List<Address> loc = geocoder.getFromLocationName(staddress, 5);
         Address addr = loc.get(0);
            //myLocation.setLatitude(addr.getLatitude());
            //myLocation.setLongitude(addr.getLongitude());
            mMap.addMarker(new MarkerOptions().draggable(true).position(new LatLng(addr.getLatitude(), addr.getLongitude())).title("Marker"));
        }
        catch(IOException e) {
         Log.e("IOException", e.getMessage()); 
         Toast.makeText(this, "IOException:  " + e.getMessage(),20).show();
        }


        //mMap.addMarker(new MarkerOptions().draggable(true).position(new LatLng(0, 0)).title("Marker"));

    }

如何在地图上显示ContactAddressQuery.ADDRESS?

对不起,我的英语不好。

EN

回答 1

Stack Overflow用户

发布于 2014-08-02 15:32:54

代码语言:javascript
复制
// create marker 
MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title(staddress);  

然后再展示这个吗?

另一种选择是使用FrameLayout。地图将被添加到底部,TextView将以透明或半透明的背景漂浮在其上。然后,您可以更改此TextView的文本以显示地址。

图片是from this blog post拍摄的

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25092762

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档