How To Replace Marker Image With Textview In Google Maps Api For Android?
I have looked everywhere , yet i can not find an answer . I want to display the marker info right away, without the need to click on it in order to see the info . I tried all answ
Solution 1:
I used the example provided at: Google Maps Android API Utility Library
specifically this github demo code class
/*
* Copyright 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.maps.android.utils.demo;
import android.graphics.Color;
import android.text.SpannableStringBuilder;
import android.text.style.StyleSpan;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.maps.android.ui.IconGenerator;
import static android.graphics.Typeface.BOLD;
import static android.graphics.Typeface.ITALIC;
import static android.text.Spannable.SPAN_EXCLUSIVE_EXCLUSIVE;
public class IconGeneratorDemoActivity extends BaseDemoActivity {
@Override
protected void startDemo() {
getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.8696, 151.2094), 10));
IconGenerator iconFactory = new IconGenerator(this);
addIcon(iconFactory, "Default", new LatLng(-33.8696, 151.2094));
iconFactory.setColor(Color.CYAN);
addIcon(iconFactory, "Custom color", new LatLng(-33.9360, 151.2070));
iconFactory.setRotation(90);
iconFactory.setStyle(IconGenerator.STYLE_RED);
addIcon(iconFactory, "Rotated 90 degrees", new LatLng(-33.8858, 151.096));
iconFactory.setContentRotation(-90);
iconFactory.setStyle(IconGenerator.STYLE_PURPLE);
addIcon(iconFactory, "Rotate=90, ContentRotate=-90", new LatLng(-33.9992, 151.098));
iconFactory.setRotation(0);
iconFactory.setContentRotation(90);
iconFactory.setStyle(IconGenerator.STYLE_GREEN);
addIcon(iconFactory, "ContentRotate=90", new LatLng(-33.7677, 151.244));
iconFactory.setRotation(0);
iconFactory.setContentRotation(0);
iconFactory.setStyle(IconGenerator.STYLE_ORANGE);
addIcon(iconFactory, makeCharSequence(), new LatLng(-33.77720, 151.12412));
}
private void addIcon(IconGenerator iconFactory, CharSequence text, LatLng position) {
MarkerOptions markerOptions = new MarkerOptions().
icon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon(text))).
position(position).
anchor(iconFactory.getAnchorU(), iconFactory.getAnchorV());
getMap().addMarker(markerOptions);
}
private CharSequence makeCharSequence() {
String prefix = "Mixing ";
String suffix = "different fonts";
String sequence = prefix + suffix;
SpannableStringBuilder ssb = new SpannableStringBuilder(sequence);
ssb.setSpan(new StyleSpan(ITALIC), 0, prefix.length(), SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.setSpan(new StyleSpan(BOLD), prefix.length(), sequence.length(), SPAN_EXCLUSIVE_EXCLUSIVE);
return ssb;
}
}
Post a Comment for "How To Replace Marker Image With Textview In Google Maps Api For Android?"