//google maps Api $("#companyform_showonmap_page").click(function(){ var geocoder; var map; function initialize() { geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng(-34.397, 150.644); var myOptions = { zoom: 17, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP, timeout: 6000, maximumAge: 50000, enableHighAccuracy:true } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); } /* if ((company.getcompanygpslalo(gpslalo)!=0) && (company.getcompanygpslalo(gpslalo)!= null)){ map.setCenter(company.getcompanygpslalo(gpslalo)); // console.log(results[0].geometry.location.Ua); // console.log(results[0].geometry.location.Va); var marker = new google.maps.Marker({ map: map, position: company.getcompanygpslalo(gpslalo) }); }else{*/ function codeAddress() { var address = document.getElementById("address").value; var gps = company.getgpslalo(); // geocoder.geocode( { 'address': $("#companyform_gpscoords").val()}, function(results, status) { // adress JSON console.log(company.getgpslalo(gps)); console.log(gps.la); console.log(gps.lo); if ((gps.la)>0 &&(gps.la)>0) { map.setCenter(new google.maps.LatLng((gps.la),(gps.lo))); pos = new google.maps.LatLng((gps.la),(gps.lo)); // console.log(results[0].geometry.location.Ua); // console.log(results[0].geometry.location.Va); var marker = new google.maps.Marker({ map: map, position: pos }); } else { // input' address if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); // console.log(results[0].geometry.location.Ua); // console.log(results[0].geometry.location.Va); var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location }); } else { alert(" : " + status); } //company.getcompanycoordinats(results[0].geometry.location.Ua,results[0].geometry.location.Va); } }); } function loadScript() { var script = document.createElement("script"); script.type = "text/javascript"; script.src = "http://maps.google.com/maps/api/js?sensor=true&callback;=initialize"; document.body.appendChild(script); } window.onload = loadScript; $.mobile.changePage("#companyform_showonmap_page"); window.onload = initialize(); window.onload = codeAddress(); });
<div id="map_canvas" style="width: 100%; height: 500px; position:center;" ></div>
$( "#map-page" ).live( "pageshow", function() var defaultLatLng = new google.maps.LatLng(37.530073, 15.112151); if ( navigator.geolocation ) { function success(pos) { // Location found, show coordinates on map drawMap(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude)); } function fail() { drawMap(defaultLatLng); // Show default map } // Find users current position navigator.geolocation.getCurrentPosition(success, fail, {enableHighAccuracy:true, timeout: 6000, maximumAge: 50000 }); } else { drawMap(defaultLatLng); // No geolocation support } function drawMap(latlng) { var myOptions = { zoom: 17, center: latlng, zoomControl: true, scaleControl: true, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map( document.getElementById("map-canvas"), myOptions); // Add an overlay to the map of current lat/lng var marker = new google.maps.Marker({ position: latlng, map: map, title: " !" }); } });
{enableHighAccuracy:true, timeout: 6000, maximumAge: 50000 }
// Jquery , $.getDocHeight = function(){ return Math.max( $(document).height(), $(window).height(), /* For opera: */ document.documentElement.clientHeight ); }; //alert( $.getDocHeight() ); $(".googlemap").height($.getDocHeight()-10); // googlemap $(".googlemap").width("98%");// googlemap`
<div id="map_canvas" class="googlemap" style="position:center" ></div>
Source: https://habr.com/ru/post/140705/
All Articles