Reputation: 3506
$coordinate
variable = 42.6358311,-71.3290596alert( coordinates );
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder = new google.maps.Geocoder();
var address = "410 walker street Lowell MA 01851";
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
var coordinates = [latitude , longitude];
alert( coordinates );
}
});
</script>
Note : 410 walker street Lowell MA 01851 -> 42.6358311,-71.3290596
<iframe
width="200"
height="200"
frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/view?key=**********
¢er= 42.6358311,-71.3290596
&zoom=18
&maptype=satellite"
>
</iframe>
If I run this code I will get this result
So far everything work, you might wondering, since everything work why am I asking ?
Here is my question, rather than inputing the latitude and the longitude manually in ¢er= 42.6358311,-71.3290596
I was wondering, if I can print out
whatever stored inside my $coordinate
variable.
Can someone please help me how to do that ? I just want to print out my $coordinate variable as part of my HTML attribute.
Upvotes: 0
Views: 152
Reputation: 1681
Try this code snippet, may be this help you...
var geocoder = new google.maps.Geocoder();
var address = "410 walker street Lowell MA 01851";
geocoder.geocode({
'address': address
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
var coordinates = [latitude , longitude];
var mapOptions = {
zoom: 18,
center: new google.maps.LatLng(latitude, longitude),
mapTypeId: google.maps.MapTypeId.SATELLITE
};
map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
document.getElementById('myText').value = coordinates;
}
});
<script src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>
<div id="map_canvas" style="width:500px; height:200px"></div>
<br />
<p>Print out your coordinate : </p><input type="text" id="myText" >
do you want to print out like this ? Please correct me if I'm wrong..
Upvotes: 1
Reputation: 161404
"Highlight a place or an address" gives me this result:
<iframe width="600" height="450" frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/place?q=410+walker+street+Lowell+MA+01851
&key=..."></iframe>
Upvotes: 1