/ / Po prostu widok mapy Google w Railsach - ruby-on-rails, google-maps

Po prostu widok mapy Google w Railsach - ruby-on-rails, google-maps

W mojej aplikacji chcę dodać Mapę Google z zaznaczoną lokalizacją, np. Pokazać lokalizację firmy dla klientów .Jak najprościej zrobić to w Railsach?

Odpowiedzi:

0 dla odpowiedzi № 1

Możesz użyć javascript mapy Google w swoim htmlplik i może pokazać mapę google. Przykładowo, jeśli chcesz pokazać mapę, która pokazuje Twoją bieżącą lokalizację na mapie google, skorzystaj z tego linku, a uzyskasz dobry przykład i dostosuj go do swoich wymagań. geolokalizacja


0 dla odpowiedzi nr 2

możesz użyć Google-Maps-for-Rails klejnot lub Mapy Google z szynami dla szczegółowego wdrożenia mapy


0 dla odpowiedzi № 3

Wypróbuj ten przykład dla mapy google z geolokalizacją.

<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
#map {
width: 750px;
height: 500px;
}
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>

<script type="text/javascript">

google.maps.event.addDomListener(window, "load", init);

function init() {
var mapOptions = {
zoom: 11,
center: new google.maps.LatLng(40.6700, -73.9400)
};

var mapElement = document.getElementById("map");

var map = new google.maps.Map(mapElement, mapOptions);

if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var latlng = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
var infowindow = new google.maps.InfoWindow();

geocoder = new google.maps.Geocoder();
geocoder.geocode({"latLng": latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
map.setZoom(11);
marker = new google.maps.Marker({
position: latlng,
map: map
});
infowindow.setContent("Your location = " + results[1].formatted_address);
infowindow.open(map, marker);

} else {
alert("No results found");
}
} else {
alert("Geocoder failed due to: " + status);
}
});
}, function() {
handleNoGeolocation(true);
});
} else {
handleNoGeolocation(false);
}

function handleNoGeolocation(errorFlag) {
if (errorFlag) {
var content = "Error: The Geolocation service failed.";
} else {
var content = "Error: Your browser doesn"t support geolocation.";
}

var options = {
map: map,
position: new google.maps.LatLng(60, 105),
content: content
};

var infowindow = new google.maps.InfoWindow(options);
map.setCenter(options.position);
}
}
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>