Android中谷歌地图标记的自定义信息窗口

时间:2014-09-25 05:46:46

标签: java android google-maps

我正在开发一个有谷歌地图的项目。我想创建一个自定义信息窗口。所以我创建了一个xml文件并在代码中执行了以下操作:

xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#00FF7F" >

    <TextView
        android:id="@+id/tv_lat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#DC143C"
         />

    <TextView
        android:id="@+id/tv_lng"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#DC143C"
         />

</LinearLayout>

主要班级:

package com.example.marinamapseg;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.InfoWindowAdapter;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;


import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends FragmentActivity {
    // Google Map
    private GoogleMap googleMap;
    GPSTracker gps;
    double current_latitude,current_longitude;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try {
            // Loading map
            initilizeMap();

        } catch (Exception e) {
            e.printStackTrace();
        }
        googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {

            @Override
            public View getInfoWindow(Marker arg0) {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public View getInfoContents(Marker arg0) {
                View v = getLayoutInflater().inflate(R.layout.info_window_layout, null);

                // Getting the position from the marker
                LatLng latLng = arg0.getPosition();

                // Getting reference to the TextView to set latitude
                TextView tvLat = (TextView) v.findViewById(R.id.tv_lat);

                // Getting reference to the TextView to set longitude
                TextView tvLng = (TextView) v.findViewById(R.id.tv_lng);

                // Setting the latitude
                tvLat.setText("Latitude:" + latLng.latitude);

                // Setting the longitude
                tvLng.setText("Longitude:"+ latLng.longitude);

                // Returning the view containing InfoWindow contents
                return v;
            }
        });

    }
    private void initilizeMap() {
        if (googleMap == null) {
            googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

            // check if map is created successfully or not
            if (googleMap == null) {
                Toast.makeText(getApplicationContext(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show();
            }
        }
        else
        {
            getcurrentlocation();
        }
    }
public void getcurrentlocation()
{
    gps=new GPSTracker(MainActivity.this);
    if(gps.canGetLocation())
    {
        current_latitude=gps.getLatitude();
        current_longitude=gps.getLongitude();
        //initialiseMap();
        placemarkersonmap();
    }
    else
    {
    gps.showSettingsAlert();
    }
}
public void placemarkersonmap()
{

    googleMap.setMyLocationEnabled(true);
    googleMap.getUiSettings().setMyLocationButtonEnabled(true);

    LatLng latLng = new LatLng(current_latitude, current_longitude);

    googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 12f));
    googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 12f));

    MarkerOptions marker = new MarkerOptions().position(new LatLng(8.505439, 76.971293));


 googleMap.addMarker(marker);

}
    @Override
    protected void onResume() {
        super.onResume();
        initilizeMap();
    }

}

问题是,当我点击信息窗口时,信息窗口的外边框显示为白色,其中显示我的自定义xml。我已在xml文件中给出了填充父级,但仍然是白色边框如何删除白色边框?

0 个答案:

没有答案