OnInfo WindowClick方法在android中不起作用

OnInfo WindowClick方法在android中不起作用,android,android-maps-v2,Android,Android Maps V2,我已经创建了一个应用程序,其中显示了我在地图中的当前位置。我想在toast消息中的OnInfo WindowClick方法下显示位置。但是吐司不起作用。提前感谢您的帮助 这是我的密码: public class SearchProviderLocation extends Activity implements LocationListener,OnInfoWindowClickListener { class MyInfoWindowAdapter implements InfoWin

我已经创建了一个应用程序,其中显示了我在地图中的当前位置。我想在toast消息中的OnInfo WindowClick方法下显示位置。但是吐司不起作用。提前感谢您的帮助

这是我的密码:

public  class SearchProviderLocation extends Activity implements LocationListener,OnInfoWindowClickListener   {

class MyInfoWindowAdapter implements InfoWindowAdapter{

    private final View myContentsView;

    MyInfoWindowAdapter(){
        myContentsView = getLayoutInflater().inflate(R.layout.custom_info_contents, null);
    }

    @Override
    public View getInfoContents(Marker marker) {

        TextView tvTitle = ((TextView)myContentsView.findViewById(R.id.title));
        tvTitle.setText(marker.getTitle());
        TextView tvSnippet = ((TextView)myContentsView.findViewById(R.id.snippet));
        tvSnippet.setText(marker.getSnippet());

        return myContentsView;
    }

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

}


final int RQS_GooglePlayServices = 1;
TextView tvLocInfo;
GoogleMap map;
private LocationManager locationManager;
protected LocationListener locationListener;
protected Context context;
String provider;
double latitude;
protected double longitude; 
protected boolean gps_enabled,network_enabled;

private String val,val1;
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000; // in Milliseconds

boolean isGPSEnabled ;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search_provider_location);


    try {

        LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
           lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
               map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                .getMap();

               map.setInfoWindowAdapter(new MyInfoWindowAdapter());

         }      

    catch (Exception e) {
            e.printStackTrace();
                        }
}


@Override
public void onLocationChanged(Location location) {
    // TODO Auto-generated method stub

    map.clear();

    Geocoder geo = new Geocoder(this.getApplicationContext(), Locale.getDefault());
  try {
        List<Address> addresses = geo.getFromLocation(location.getLatitude(), location.getLongitude(), 1);

        MarkerOptions mp = new MarkerOptions();

           mp.position(new LatLng(location.getLatitude(), location.getLongitude()));
           mp.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker));

           mp.snippet("Address:"+" "+" "+addresses.get(0).getFeatureName()+" "+addresses.get(0).getAdminArea()+" "+addresses.get(0).getLocality()+" "+addresses.get(0).getPostalCode()+""+addresses.get(0).getCountryCode());
           mp.title(addresses.get(0).getLocality()+", "+addresses.get(0).getCountryName());

           map.addMarker(mp);
           map.animateCamera(CameraUpdateFactory.newLatLngZoom(
            new LatLng(location.getLatitude(), location.getLongitude()), 14)); 
  } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

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

    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

    if (resultCode == ConnectionResult.SUCCESS){
        Toast.makeText(getApplicationContext(), 
                "GooglePlayServicesAvailable", 
                Toast.LENGTH_LONG).show();
    }else{
        GooglePlayServicesUtil.getErrorDialog(resultCode, this, RQS_GooglePlayServices);    
    }
}

public void onMapLongClick(LatLng point) {
    tvLocInfo.setText("New marker added@" + point.toString());

    Marker newMarker = map.addMarker(new MarkerOptions()
                                .position(point)
                                .snippet(point.toString()));
    newMarker.setTitle(newMarker.getId());

}
@Override
public void onInfoWindowClick(Marker marker)
{
   marker.getTitle();
   final String ssid = marker.getTitle(); 

   Toast.makeText(getBaseContext(),"You click @" + ssid,Toast.LENGTH_SHORT).show();

}

@Override
public void onProviderDisabled(String provider) {

}

@Override
public void onProviderEnabled(String provider) {


}                   

@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
    // TODO Auto-generated method stub

}}
公共类SearchProviderLocation扩展活动实现LocationListener,OnInfo窗口ClickListener{
类MyInfoWindowAdapter实现InfoWindowAdapter{
私有最终视图myContentsView;
MyInfoWindowAdapter(){
myContentsView=getLayoutFlater().充气(R.layout.custom\u info\u contents,null);
}
@凌驾
公共视图getInfoContents(标记器){
TextView tvTitle=((TextView)myContentsView.findViewById(R.id.title));
tvTitle.setText(marker.getTitle());
TextView tvSnippet=((TextView)myContentsView.findViewById(R.id.snippet));
tvsippet.setText(marker.getSnippet());
返回myContentsView;
}
@凌驾
公共视图getInfoWindow(标记器){
//TODO自动生成的方法存根
返回null;
}
}
最终int RQS_GooglePlayServices=1;
TextView-tvLocInfo;
谷歌地图;
私人场所经理场所经理;
受保护的LocationListener LocationListener;
受保护的语境;
字符串提供者;
双纬度;
保护双经度;
受保护布尔值gps_启用,网络_启用;
私有字符串val,val1;
私有静态最终最短长\u距离\u更改\u用于\u更新=1;//以米为单位
私有静态最终最长最短\u更新间隔时间\u=1000;//以毫秒为单位
布尔isGPSEnabled;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u search\u provider\u location);
试一试{
LocationManager lm=(LocationManager)getSystemService(Context.LOCATION\u服务);
lm.RequestLocationUpdate(LocationManager.NETWORK_提供程序,0,0,this);
map=((MapFragment)getFragmentManager().findFragmentById(R.id.map))
.getMap();
setInfoWindowAdapter(新的MyInfoWindowAdapter());
}      
捕获(例外e){
e、 printStackTrace();
}
}
@凌驾
已更改位置上的公共无效(位置){
//TODO自动生成的方法存根
map.clear();
Geocoder geo=新的Geocoder(this.getApplicationContext(),Locale.getDefault());
试一试{
列表地址=geo.getFromLocation(location.getLatitude(),location.getLatitude(),1);
MarkerOptions mp=新的MarkerOptions();
mp.位置(新车床(location.getLatitude(),location.getLongitude());
icon(BitmapDescriptorFactory.fromResource(R.drawable.marker));
mp.snippet(“地址:”+“+”+”+地址。get(0)。getFeatureName()+”+地址。get(0)。getAdminArea()+“+地址。get(0)。GetLocation()+”+地址。get(0)。getPostalCode()+”+地址。get(0)。getCountryCode());
mp.title(addresses.get(0.getLocation()+”,“+addresses.get(0.getCountryName());
map.addMarker(mp);
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
新的LatLng(location.getLatitude(),location.getLongitude()),14);
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}
@凌驾
受保护的void onResume(){
super.onResume();
int-resultCode=GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if(resultCode==ConnectionResult.SUCCESS){
Toast.makeText(getApplicationContext(),
“GooglePlayServicesAvailable”,
Toast.LENGTH_LONG).show();
}否则{
GooglePlayServicesUtil.getErrorDialog(结果代码,this,RQS_GooglePlayServices);
}
}
在马普隆喀喇克(LatLng点)上的公共空隙{
tvLocInfo.setText(“添加了新标记@”+point.toString());
Marker newMarker=map.addMarker(新MarkerOptions()
.位置(点)
.snippet(point.toString());
setTitle(newMarker.getId());
}
@凌驾
公用无效信息窗口单击(标记)
{
marker.getTitle();
最后一个字符串ssid=marker.getTitle();
Toast.makeText(getBaseContext(),“单击@”+ssid,Toast.LENGTH_SHORT).show();
}
@凌驾
公共无效onProviderDisabled(字符串提供程序){
}
@凌驾
公共无效onProviderEnabled(字符串提供程序){
}                   
@凌驾
状态已更改的公共void(字符串arg0、整数arg1、捆绑包arg2){
//TODO自动生成的方法存根
}}
尝试以下代码:

map.setOnInfoWindowClickListener(new OnInfoWindowClickListener()
{
    @Override public void onInfoWindowClick(Marker arg0) {
        final String ssid = arg0.getTitle(); 
        Toast.makeText(SearchProviderLocation.this,"You click @" + ssid,Toast.LENGTH_SHORT).show();
    }
}); 
请尝试以下代码:

map.setOnInfoWindowClickListener(new OnInfoWindowClickListener()
{
    @Override public void onInfoWindowClick(Marker arg0) {
        final String ssid = arg0.getTitle(); 
        Toast.makeText(SearchProviderLocation.this,"You click @" + ssid,Toast.LENGTH_SHORT).show();
    }
}); 

天啊!你成功了!那是awesome@IntellijAmiya你是如何解决你的问题的。。我也有同样的问题。。toast在OnInfo窗口中不起作用Click它对我不起作用。这就是我问的原因。它现在起作用了..你接受的答案是对的,实际上我是在点击marker,当我意识到它唯一起作用的时候,点击infoWindow.OMG!你成功了!那是awesome@IntellijAmiya你是如何解决你的问题的。。我也有同样的问题。。toast在OnInfo窗口中不起作用Click它对我不起作用。这就是我问的原因。它现在起作用了..你接受的答案是对的,实际上我是在点击marker,当我意识到它唯一的作用是点击infoWindow时。别忘了添加类似于
googleMap.setOnInfoWindowLongClickListener的内容(这个)
onMapReady
:)不要忘记在
onMapReady
:)中添加类似于
googleMap.setOnInfoWindowLongClickListener(此)