为Google地图标记创建一个特定地址

时间:2016-04-29 08:01:58

标签: java android google-maps

我的应用中有谷歌地图活动。 我想输入某个地点的特定地址,我希望该应用能够将其转换为Google地图标记。

到现在为止,我已经放了一个LatLng鳕鱼,就像这样:

double location_left = Double.parseDouble(leftLocation);
double location_right = Double.parseDouble(rightLocation);
String place_title = child.child("place/place_title").getValue().toString();
LatLng cod = new LatLng(location_left, location_right);
googleMap.addMarker(new MarkerOptions().position(cod).title(place_title));

有没有选择在LatLng鳕鱼上制作像“Covert St New York,United States”这样的特定地址?或谷歌地图标记?

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

此功能返回 Google地图图片的输入地址,您可以将其更改为 LatLng

public static String getLocationURLFromAddress(Context context,
        String strAddress) {

    Geocoder coder = new Geocoder(context);
    List<android.location.Address> address;
    LatLng p1 = null;

    try {
        address = coder.getFromLocationName(strAddress, 5);
        if (address == null) {
            return null;
        }
        android.location.Address location = address.get(0);
        location.getLatitude();
        location.getLongitude();

        return "http://maps.googleapis.com/maps/api/staticmap?zoom=18&size=560x240&markers=size:mid|color:red|"
                + location.getLatitude()
                + ","
                + location.getLongitude()
                + "&sensor=false";

        //
        // p1 = new LatLng(location.getLatitude(), location.getLongitude());

    } catch (Exception ex) {

        ex.printStackTrace();
    }
    return strAddress;

    // return p1;
}

您可以在Picasso或Glide的帮助下直接加载地址的图片网址,或者如果您想在地图中制作标记,您可以执行以下操作: -

private void addMarker( LatLng currentLatLng ) {

            MarkerOptions options = new MarkerOptions();

            // following four lines requires 'Google Maps Android API Utility Library'
            // https://developers.google.com/maps/documentation/android/utility/
            // I have used this to display the time as title for location markers
            // you can safely comment the following four lines but for this info

            IconGenerator iconFactory = new IconGenerator(this);

            iconFactory.setStyle(IconGenerator.STYLE_PURPLE);
            options.icon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon(mLastUpdateTime)));
            options.anchor(iconFactory.getAnchorU(), iconFactory.getAnchorV());


            Marker mapMarker = googleMap.addMarker(options);

            long atTime = mCurrentLocation.getTime();

            mLastUpdateTime = DateFormat.getTimeInstance().format(new Date(atTime));

            mapMarker.setTitle(mLastUpdateTime);

            Log.d(TAG, "Marker added.............................");
            googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng,
                    13));
            Log.d(TAG, "Zoom done.............................");
        }