Labelling on Google Maps SDK For Android - google-maps

I am wanting to put my own custom label over certain places on a map, take for example the image below where there is text for Albert Park Lake which is not associated with a place marker. This is an example of what I am wanting to do as I am designing an app that has a number of regions and I wanting to put the names of those regions on the map which will only be visible at certain zoom levels as to ensure there is no clutter when being viewed by the user. I had experimented with place markers but found that the text being on top of the marker was bad look and I would have had to write a function to adjust the text visibility for the zoom level to deal with the clutter of many being on the screen at once.
Cheers Jordan Smith

I suggest to convert the text you want to set to bitmap image and set this bitmap as custom marker, you may find this question useful if you want to know how to convert text to bitmap.

Here are a few things you could try:
1. Pop up multiple infowindows: https://jsfiddle.net/kjqfs0bo/
function initMap() {
const uluru = { lat: -25.363, lng: 131.044 };
const map = new google.maps.Map(document.getElementById("map"), {
zoom: 4,
center: uluru,
});
const contentString ="lalala";
const infowindow = new google.maps.InfoWindow({
content: contentString,
});
const infowindow2 = new google.maps.InfoWindow({
content: contentString,
});
const marker = new google.maps.Marker({
position: uluru,
map,
title: "Uluru (Ayers Rock)",
});
const marker2 = new google.maps.Marker({
position: { lat: -20.363, lng: 130.044 },
map,
title: "Uluru (Ayers Rock)",
});
infowindow.open(map, marker);
infowindow2.open(map, marker2);
}
2. Invisible markers with text label: https://jsfiddle.net/0koynbz2/1/
function createMarker() {
var canvas, context;
canvas = document.createElement("canvas");
return canvas.toDataURL();
}
var map = new google.maps.Map(document.getElementById("map_canvas"), {
zoom: 13,
center: new google.maps.LatLng(56.1304, -106.3468),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var marker = new google.maps.Marker({
position: new google.maps.LatLng(56.1304, -106.3468),
map: map,
icon: {
url: createMarker()
},
label: {
text: 'My Place',
color: '#000',
fontSize: '14px',
fontWeight: 'bold'
}
});
var marker2 = new google.maps.Marker({
position: new google.maps.LatLng(56.1204, -106.3468),
map: map,
icon: {
url: createMarker()
},
label: {
text: 'My Place2',
color: '#000',
fontSize: '14px',
fontWeight: 'bold'
}
});
3. Maybe try geojson, but since geojson only supports point, line and polygon. I'm not sure if there is a way to display text only.

Related

Google Maps: How to change Marker default red color and add label

I think this should be rather easy at first. However It takes me many hours searching on the Internet without getting a solution.
I can add a Marker on a Google Map with Label, as below:
// Adding a marker to the map
var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(22.48, 114.20),
map: map,
title: 'My House',
label: {
text: 'A',
color: '#79E149'
}
});
The default color is red.
My question:
How can I change the Red color of Marker to other color, for example, Green?
I noticed that most answers suggest to use an external icon, for example:
// Adding a marker to the map
var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(22.48, 114.20),
map: map,
title: 'My House',
**icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png',**
label: {
text: 'A',
color: '#79E149'
}
});
However:
1. The label will not appear when use this kind of icons.
Actually I don't want to use external image as the URL may be changed later. In fact many icons seems disappear already, for example:
http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/blank.png
Thanks and best regards
Alex
Your label text is green (#79E149) so it blends in with the marker
You probably don't want a "dot" on the marker if you want to put a label on it (change the marker icon's name to "green" from "green-dot").
The LabelOrigin of the icon is wrong for that particular marker/label combination
proof of concept fiddle
code snippet:
var geocoder;
var map;
function initialize() {
var map = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(22.48, 114.20),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
// Adding a marker to the map
var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(22.48, 114.20),
map: map,
title: 'My House',
icon: {
url: 'http://maps.google.com/mapfiles/ms/icons/green.png',
labelOrigin: new google.maps.Point(15, 10)
},
label: {
text: 'A',
color: 'black'
}
});
var marker2 = new google.maps.Marker({
position: new google.maps.LatLng(22.49194, 114.204426),
map: map,
title: 'My Other House',
icon: {
url: 'http://maps.google.com/mapfiles/ms/icons/orange.png',
labelOrigin: new google.maps.Point(15, 10)
},
label: {
text: 'B',
color: 'black'
}
});
}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas"></div>
Try this
GoogleMap googlemap;
googlemap.addMarker(new MarkerOptions()
.position(new LatLng( 22.48, 114.20))
.title("My House").snippet("A").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));

How to dynamically change the centre of a google maps?

var mapOptions = {
zoom: 14,
center: new google.maps.LatLng(lattitude,langitude),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
dynamically change the centre of a google maps please any one tel
var marker = new google.maps.Marker({
position: new google.maps.LatLng(latitude, longitude),
title: markerTitle,
map: map,
});
google.maps.event.addListener(marker, 'click', function () {
map.panTo(marker.getPosition());//sets center with animation
//map.setCenter(marker.getPosition()); // sets center without animation
});

Map markers in street view

First of all, I'm not really sure if this question is really for Stack Overflow, please tell me where I should move it if it's necessary.
Is it possible to add custom pins (map markers) in Google Maps Street View? If the answer is "yes" please provide additional information about how it can be done (links to sources, tips, etc.). Tried searching on Google for "google maps street view markers" but I couldn't find anything relevant.
Yes is possible
you can easy found sample like this on google dev
this is the js sample code by google development
var panorama;
function initMap() {
var astorPlace = {lat: 40.729884, lng: -73.990988};
// Set up the map
var map = new google.maps.Map(document.getElementById('map'), {
center: astorPlace,
zoom: 18,
streetViewControl: false
});
// Set up the markers on the map
var cafeMarker = new google.maps.Marker({
position: {lat: 40.730031, lng: -73.991428},
map: map,
icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe|FFFF00',
title: 'Cafe'
});
var bankMarker = new google.maps.Marker({
position: {lat: 40.729681, lng: -73.991138},
map: map,
icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=dollar|FFFF00',
title: 'Bank'
});
var busMarker = new google.maps.Marker({
position: {lat: 40.729559, lng: -73.990741},
map: map,
icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=bus|FFFF00',
title: 'Bus Stop'
});
// We get the map's default panorama and set up some defaults.
// Note that we don't yet set it visible.
panorama = map.getStreetView();
panorama.setPosition(astorPlace);
panorama.setPov(/** #type {google.maps.StreetViewPov} */({
heading: 265,
pitch: 0
}));
}
function toggleStreetView() {
var toggle = panorama.getVisible();
if (toggle == false) {
panorama.setVisible(true);
} else {
panorama.setVisible(false);
}
}

get selected marker google maps api 3

in the following code generated an undetermined number of markers, this works well.
for(i=0;i<idr.length;i++){
var LatLng = new google.maps.LatLng(lat[i], lng[i]);
m[i] = new google.maps.Marker({
position: LatLng,
icon: image,
map: map,
draggable: false,
val: idr[i]
});
}
I want to get the properties of the corresponding marker when the mouse passes over this
This does not apply for you should create a function for each marker and can not be that many
This function only access the first marker
google.maps.event.addListener(m[0], "click", function(e) {
var latitud = e.latLng.lat();
alert(latitud);
});
use this inside the callback to get access to the current marker(m[i] will not work there, because it will always refer to the last created marker)
google.maps.event.addListener(m[i], 'mouseover', function() {
alert(this.val)
});
for(i=0;i<idr.length;i++){
var LatLng = new google.maps.LatLng(lat[i], lng[i]);
m[i] = new google.maps.Marker({
position: LatLng,
icon: image,
map: map,
draggable: false,
val: idr[i]
});
google.maps.event.addListener(m[i], 'mouseover', function() {
//Do stuff
});
}
The above is how I would do it.

Change pin label in google maps?

How can I change the label for pins in an embedded google maps?
Ive figured out how to change the marker to my icon, but I need to restyle the A, B, C etc similar to how travelodge do for there map http://www.travelodge.co.uk/hotels/book/edinburgh-hotels
UPDATE this is the code that successfully uses a custom marker:
function addMarker(latlng, myTitle) {
markers.push(new google.maps.Marker({
position: latlng,
map: map,
title: myTitle,
icon: "www.linkto/myPin.png"
}));
}
Ive included markerwithlabel.js However this doesn't create any markers at all:
function addMarker(latlng, myTitle) {
markers.push(new MarkerWithLabel({
position: latlng,
map: map,
title: myTitle,
icon: "www.linkto/myPin.png",
labelContent: "$425K",
labelAnchor: new google.maps.Point(22, 0),
labelClass: "labels",
labelStyle: {opacity: 0.75}
}));
}
This is the code I was tying to adapt:
http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerwithlabel/1.1.8/examples/basic.html
If you managed to change the marker icon, then you did all the work.
A marker does not have a label. What travelodge does is that it has markers for each letter and then sets them according to the search results.
EDIT:
It seems there's a special library to do what you want (go to "Styled Marker"):
http://code.google.com/p/google-maps-utility-library-v3/wiki/Libraries#MarkerWithLabel
To see the code click in "Development versions", then "Examples" and then look at the source code of the pages. Here's the Simple example code:
function initialize() {
var myLatLng = new google.maps.LatLng(37.313477473067, -121.880502070713);
var myOptions = {
zoom: 11,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.SATELLITE
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var styleMaker2 = new StyledMarker({styleIcon:new StyledIcon(StyledIconTypes.BUBBLE,{color:"ff0000",text:"I'm a marker!"}),position:new google.maps.LatLng(37.383477473067, -121.880502070713),map:map});
var styleMaker1 = new StyledMarker({styleIcon:new StyledIcon(StyledIconTypes.MARKER,{color:"00ff00",text:"A"}),position:myLatLng,map:map});
var styleMaker3 = new StyledMarker({styleIcon:new StyledIcon(StyledIconTypes.MARKER,{color:"0000ff"}),position:new google.maps.LatLng(37.263477473067, -121.880502070713),map:map});
}
You can read more about markers on this link