我試圖創建自己的信息窗口,但當我運行它,我有這些錯誤:如何爲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>
有誰知道最新錯了?
謝謝。
謝謝你很多! – Oli
當您點擊infoWindow時,您能告訴我如何製作全屏infoWindow嗎? – Oli