I'm developing in google maps APIv2. The issue that I'm facing now is I only able to add in one line of word in info windows/snippet. But the output that I want is able to display in break line form as example show below. So is there any possible methods to solve it?
Example:
Coordinate: 03.05085, 101.70506
Speed Limit: 80 km/h
public class MainActivity extends FragmentActivity {
static final LatLng SgBesi = new LatLng(03.05085, 101.76022);
static final LatLng JB = new LatLng(1.48322, 103.69065);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
map.addMarker(new MarkerOptions().position(SgBesi)
.title("KM D7.7 Sungai Besi") //name
.snippet("Coordinate: 03.05085, 101.70506")); //description
map.addMarker(new MarkerOptions().position(JB)
.title("test")
.snippet("Hey, how are you?"));
// .icon(BitmapDescriptorFactory //set icon
// .fromResource(R.drawable.ic_launcher)));
// move the camera instantly with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(SgBesi, 15));
// zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
}
}
You need to use a custom InfoWindowAdapter to change the layout of InfoWindow
to a custom design defined using a layout file. Basically you need to :
GoogleMap.setInfoWindowAdapter(Yourcustominfowindowadpater)
...
class Yourcustominfowindowadpater implements InfoWindowAdapter {
private final View mymarkerview;
Yourcustominfowindowadpater() {
mymarkerview = getLayoutInflater()
.inflate(R.layout.custominfowindow, null);
}
public View getInfoWindow(Marker marker) {
render(marker, mymarkerview);
return mymarkerview;
}
public View getInfoContents(Marker marker) {
return null;
}
private void render(Marker marker, View view) {
// Add the code to set the required values
// for each element in your custominfowindow layout file
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With