2017-06-15 101 views
0

试图创建自己的信息窗口,但当我运行它,我有这些错误如何为Google地图创建自定义信息窗口?

error: cannot find symbol variable LatLng

error: cannot find symbol method getPosition()

error: non-static variable latitude cannot be referenced from a static context

error: non-static variable longitude cannot be referenced from a static context

error: cannot find symbol class atLng

Error: Execution failed for task ':app:compileDebugJavaWithJavac'. Compilation failed; see the compiler error output for details.

这是我使用的代码:

import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
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.OnMapReadyCallback; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 
import com.google.android.gms.maps.model.BitmapDescriptorFactory; 
import com.google.android.gms.maps.model.BitmapDescriptor; 
import com.google.android.gms.maps.model.BitmapDescriptorFactory; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.LatLngBounds; 
import com.google.android.gms.maps.model.Marker; 
import com.google.android.gms.maps.model.MarkerOptions; 
import android.widget.TextView; 
import android.view.View; 




public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 
    private GoogleMap mMap1; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_maps); 
     // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
     SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.map); 
     mapFragment.getMapAsync(this); 
    } 

    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     mMap1 = googleMap; 
     if(mMap1 != null){ 
      mMap1.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter(){ 

      @Override 
      public View getInfoWindow(Marker marker) { 
        return null; 
      } 

      @Override 
      public View getInfoContents(Marker marker) { 
       View v = getLayoutInflater().inflate(R.layout.info_window, null); 
       TextView tvLocality = (TextView) v.findViewById(R.id.tv_locality); 
       TextView tvLat = (TextView) v.findViewById(R.id.tv_lat); 
       TextView tvLng = (TextView) v.findViewById(R.id.tv_lng); 
       TextView tvSnippet = (TextView) v.findViewById(R.id.tv_snippet); 

       LatLng = mMap1.getPosition(); 
       tvLocality.setText(marker.getTitle()); 
       tvLat.setText("Latitudine: " + LatLng.latitude); 
       tvLng.setText("Longitudine: " + LatLng.longitude); 
       tvSnippet.setText(marker.getSnippet()); 

       return v; 
      } 
      }); 


      } 


      atLng biss = new LatLng(45.758035, 21.227514); 
     mMap1.addMarker(new MarkerOptions() 
       .position(biserica) 
       .title("Church") 
       .snippet("gafhha") 
       .icon(BitmapDescriptorFactory. fromResource(R.drawable.marker))); 
     mMap1.moveCamera(CameraUpdateFactory.newLatLngZoom(biss, 14)); 
} 
} 

and info_window.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:src="@drawable/marker"/> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/tv_locality" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView" 
      android:textSize="20sp"/> 

     <TextView 
      android:id="@+id/tv_lat" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView"/> 

     <TextView 
      android:id="@+id/tv_lng" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView"/> 

     <TextView 
      android:id="@+id/tv_snippet" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView"/> 

    </LinearLayout> 

</LinearLayout> 

有谁知道最新错了?

谢谢。

回答

2

您的代码:

LatLng = mMap1.getPosition(); 
      tvLocality.setText(marker.getTitle()); 
      tvLat.setText("Latitudine: " + LatLng.latitude); 
      tvLng.setText("Longitudine: " + LatLng.longitude); 
      tvSnippet.setText(marker.getSnippet()); 

什么你做了错误

Didn't declare variable for LatLng

应该经纬度经纬度= ....

mMap1 will not have getposition()

您应该添加marker.getPosition();

same for LatLng.latitude you have to use latlng.latitude

修改后的代码

LatLng latlng= marker.getPosition(); 
       tvLocality.setText(marker.getTitle()); 
       tvLat.setText("Latitudine: " + latlng.latitude); 
       tvLng.setText("Longitudine: " + latlng.longitude); 
       tvSnippet.setText(marker.getSnippet()); 

其他错误在

atLng biss = new LatLng(45.758035, 21.227514); 
    mMap1.addMarker(new MarkerOptions() 
      .position(biserica) 
      .title("Church") 
      .snippet("gafhha") 
      .icon(BitmapDescriptorFactory. fromResource(R.drawable.marker))); 
    mMap1.moveCamera(CameraUpdateFactory.newLatLngZoom(biss, 14)); 

改变它

变化atLng经纬度

变化bisericaBISS

LatLng biss = new LatLng(45.758035, 21.227514); 
    mMap1.addMarker(new MarkerOptions() 
      .position(biss) 
      .title("Church") 
      .snippet("gafhha") 
      .icon(BitmapDescriptorFactory. fromResource(R.drawable.marker))); 
    mMap1.moveCamera(CameraUpdateFactory.newLatLngZoom(biss, 14)); 
+0

谢谢你很多! – Oli

+0

当您点击infoWindow时,您能告诉我如何制作全屏infoWindow吗? – Oli

相关问题