【问题标题】:Make a specific address to a Google Map Marker为 Google 地图标记指定具体地址
【发布时间】:2016-08-24 06:58:42
【问题描述】:

我的应用中有一个谷歌地图活动。 我想输入某个地点的特定地址,并且我希望应用程序将其添加到 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 鳕鱼?还是到谷歌地图标记?

【问题讨论】:

标签: java android google-maps


【解决方案1】:

【讨论】:

    【解决方案2】:

    此函数返回输入地址的谷歌地图图像,您可以将其更改为返回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 的帮助下直接加载地址的图片 url,或者如果您想在地图中做标记,您可以这样做:-

    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.............................");
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-27
      • 2012-09-10
      • 2016-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多