Showing posts with label Google map integration. Show all posts
Showing posts with label Google map integration. Show all posts

Monday 9 January 2017

How to integrate Google Places Search API in website?

How to integrate Google Places Search API in website?

Get the Google API Key
  1. Login to
  2. Get the API Keys.
  3. Enable "Google Places API Web Service" from Google Google Map API


<script src=";libraries=places&amp;key=HERE_YOUR_KEYS"></script>
<div class="search-Form">
<input id="search" name="q" type="text" value="" /> <input id="submit" type="submit" value="go" />

JavaScript Code

    var lat
    var lon
    function initialize() {
        var input = document.getElementById('search');
        var autocomplete = new google.maps.places.Autocomplete(input);

        google.maps.event.addListener(autocomplete, 'place_changed', function() {
            var place = autocomplete.getPlace();
            lat =
            lon = place.geometry.location.lng()


    google.maps.event.addDomListener(window, 'load', initialize);

View Demo

Saturday 11 April 2015

How can I check whether Google Maps is fully loaded in GMaps v3

Problem 1: How can I check whether Google Maps is fully loaded in GMaps v3?
Problem Description: I want to add few codes just after the google map is fully loaded in browser.

google.maps.event.addListenerOnce(map, 'idle', function(){
    // console.log('Google map is fully loaded in Gmap V3')

You can write your code inside this {}, It will be called when Google map V3 is fully loaded OR failed  to load due to any reason.

Problem 2: How can I change the color of a Google Maps marker In Gmaps 3?
Problem Description:
I want to change the color of default google markers
want to show my image instead of default google marker.
var beachMarker = new google.maps.Marker({
  position: myLatLng,
  map: map,
  icon: 'mymarker.png'

Replace the "mymarker.png" with your image including path.

Thursday 7 August 2014

Goole Map - Track your moving Position on google map- html5

Goole Map - Track your moving Position on google map- html5

This will enable to you get the current position of your location in mobile. First it will tell your current position on the Google map in form of Pushpin. When you start changing your position then pushpin will start moving. It will be follow you. But GPS and internet must be support by your mobile and off-course it should be enabled in your mobile. It will also work in 2G/3G/4G. It will give your more accurate when you are in City area.

How its work:
It will check your current position with use of browser html5 property. Thats why it ask "Are you want to share your current location".To see your position you must give the access of your current position to the browser. After getting your position it simply plot on google map. When you change your position it recheck the position with use of GPS and update the pushpin on google map.


    body {font-family: Helvetica;font-size:13pt;padding:0px;margin:0px}
    #map_canvas{display:none; height:100%; width:100%; position:relative;z-index:1;}
    #current {padding:5px; background-color:#000; position:unset; left:0px;z-index:2;text-align:center;width:90%;opacity:0.4;color:#FFF;border-radius:0px 0px 5px 5px; font-weight:bold;}
    #btnCont{position:absolute; bottom:0px; left:0px; width:100%; text-align:center;z-index:2;}</style>

<div id="current">
<div id="map_canvas" style="height: 300px; width: 800px;">
<div id="btnCont" style="display: none;">
<button onclick="startAgain();"> Restart Tracking</button>
    <button onclick="stopTracking();"> Stop Tracking</button>
<script charset="utf-8" src="//" type="text/javascript"></script>
<script src="//" type="text/javascript"></script>

    var gmap = null;
    var markers = [];
    var opts = {
        enableHighAccuracy: true,
        timeout: 60000,
        maximumAge: 0
    function initialiseMap(){
        var myOptions = {
            minZoom : 3,
            zoom: 10,
            mapTypeControl: true,
            mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
            navigationControl: true,
            navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
            mapTypeId: google.maps.MapTypeId.ROADMAP      
        gmap = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    function initialise(){
            document.getElementById('current').innerHTML="Functionality not available";
    function handle_errors(error){
        var error_str='';
            case error.PERMISSION_DENIED: 
                error_str="User(you) did not share your geolocation";
            case error.POSITION_UNAVAILABLE: 
                error_str="Could not detect current position";
            case error.TIMEOUT: 
                error_str="retrieving position timed out";
                error_str="unknown error";
    function showPosition(p){
        if(gmap == null){
            document.getElementById('map_canvas').style.display = 'block';
        var latitude = parseFloat( p.coords.latitude );
        var longitude = parseFloat( p.coords.longitude );
        document.getElementById('current').innerHTML="Lat = " + latitude.toFixed(2) +" and Long = " + longitude.toFixed(2);
        var location = new google.maps.LatLng( latitude , longitude);

        var marker = new google.maps.Marker({
            position: location,
            map: gmap,
            title:"You are here"
        var infowindow = new google.maps.InfoWindow({
            content: "<strong>This is your current location.</strong>"
        google.maps.event.addListener(marker, 'click', function() {
        document.getElementById('btnCont').style.display = 'block';
    function setAllMap(map) {
        for (var i = 0; i &lt; markers.length; i++) {
    function deleteMarkers() {
        markers = [];
    var watchID = navigator.geolocation.watchPosition(trace,handle_errors,opts);
    function trace(position){
    function startAgain(){
        watchID = navigator.geolocation.watchPosition(trace,handle_errors,opts);
    function stopTracking(){
    google.maps.event.addDomListener(window, 'load', initialise);


Thursday 17 July 2014

Google Maps - Modifying Controls

Google Maps - Modifying Controls

<script src="//"></script>
function initialize5()
 var mapProp5 = {
    center: new google.maps.LatLng(51.508742,-0.120850),
    mapTypeId: google.maps.MapTypeId.ROADMAP
var map5=new google.maps.Map(document.getElementById("googleMapId5"),mapProp5);
google.maps.event.addDomListener(window, 'load', initialize5);
<div id="googleMapId5" style="height: 300px; width: 670px;">

Google Map Integration Add InfoWindow in Marker

Many Web application show the locations on Google map like list of Hotels, Hostels, Origin & Destination in form of marker

When we click on these markers a small popup window open, that describe about that location. Its very useful functionality of Google map because we can can't show the address in Google map but we can show the Marker in Google map. 

We can show lot of markers with different categories and also these markers can be customized, means we can show our custom image instead of Google Marker. Also can do lot of animation with marker.

We can add rich text in the info popup window. means you can do bold, italic, text align and add images. You can put full address with images in the info box.

<script src="//"></script>
    /** Add lat/lng of your location **/
    var myCenter3=new google.maps.LatLng(51.508742,-0.120850);

    function initialize3()
        var mapProp3 = {

        var map3=new google.maps.Map(document.getElementById("googleMapId3"),mapProp3);

        var marker3=new google.maps.Marker({


        var infowindow = new google.maps.InfoWindow({
            content:"We are <b>web technology experts</b>, You can also add images here."
    google.maps.event.addDomListener(window, 'load', initialize3);
<div id="googleMapId3" style="height: 300px; width: 650px;">