Archit Patel
вы можете использовать этот код просто передайте местоположение в строке запроса
<html>
<head>
<script>
function getQueryStrings() {
var assoc = {};
var decode = function (s) { return decodeURIComponent(s.replace(/\+/g, " ")); };
var queryString = location.search.substring(1);
var keyValues = queryString.split('&');
for (var i in keyValues) {
var key = keyValues[i].split('=');
if (key.length > 1) {
assoc[decode(key[0])] = decode(key[1]);
}
}
return assoc;
}
var qs = getQueryStrings();
var myParam = qs["address"];
var lat = '';
var lng = '';
var marker='';
var geocoder;
var map;
function codeAddress() {
geocoder = new google.maps.Geocoder();
var address = myParam;
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
lat = results[0].geometry.location.lat(); //getting the lat
lng = results[0].geometry.location.lng(); //getting the lng
map.setCenter(results[0].geometry.location);
//add the pin point
marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
animation: google.maps.Animation.DROP,
});
//add circle in map
var draw_circle = null; // object of google maps polygon for redrawing the circle
rad = 800; // convert to meters if in miles
if (draw_circle != null) {
draw_circle.setMap(null);
}
draw_circle = new google.maps.Circle({
center: map.getCenter(),
radius: rad,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FF0000",
fillOpacity: 0.10,
map: map
});
//End of circle in map
//add the popup on pin point.
var infowindow = new google.maps.InfoWindow({
content: "<h3 style="font-family:sans-serif;">"+address+"</h3>"
});
makeInfoWindowEvent(map, infowindow, marker);
markers.push(marker);
function makeInfoWindowEvent(map, infowindow, marker) {
google.maps.event.addListener(marker, 'click', function () {
infowindow.open(map, marker);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
//End of add the popup on pin point.
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
});
//plot the map
var latlng = new google.maps.LatLng(lat, lng);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
window.onload = function () {
codeAddress();
}
</script>
<style type="text/css">
body
{
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<script src="http://maps.google.com/maps/api/js?libraries=places®ion=uk&language=en&sensor=true"></script>
<div id="map_canvas" style="height: 100%; width: 100%; margin: 0em;">
</div>
</body>
</html>
Member 10955199
Не могли бы вы дать мне знать, что такое формат строки ??
я попробовал этот код, но он не работает для меня
пожалуйста помочь