How To Implement Centered Marker In Google Maps API V3 With Ionic & Angular
I have created a map in my Ionic project using Maps API v3 and ngCordova to get my current location and with the following code: var options = {timeout: 10000, enablehighAccura
Solution 1:
This should do the trick.
Javascript
var options = {
timeout: 10000,
enablehighAccuracy: false
};
$cordovaGeolocation.getCurrentPosition(options)
.then(function(position) {
var myLat = position.coords.latitude;
var myLong = position.coords.longitude;
console.log(myLat, myLong);
var center = new google.maps.LatLng(myLat, myLong);
var mapOptions = {
center: center,
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false,
mapTypeControl: false,
zoomControl: false
};
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
//This is where the marker is added, an empty div is created, then a class of 'centerMarker' is added. Clickevents are registered and bound to the map.
$('<div/>').addClass('centerMarker').appendTo(map.getDiv())
//do something onclick
.click(function() {
var that = $(this);
if (!that.data('win')) {
that.data('win', new google.maps.InfoWindow({
content: 'this is the center'
}));
that.data('win').bindTo('position', map, 'center');
}
that.data('win').open(map);
});
}
},
function(err) {
console.log(err);
});
CSS
.centerMarker {
position: absolute;
/*url of the marker*/
background: url(http://maps.gstatic.com/mapfiles/markers2/marker.png) no-repeat;
/*center the marker*/
top: 50%;
left: 50%;
z-index: 1;
/*fix offset when needed*/
margin-left: -10px;
margin-top: -34px;
/*size of the image*/
height: 34px;
width: 20px;
cursor: pointer;
}
Post a Comment for "How To Implement Centered Marker In Google Maps API V3 With Ionic & Angular"