6

I m using google map api v3. I m using wpestate real estate wordpress theme. This is my code in template file..

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script src="https://maps.googleapis.com/maps/api/js?   
  v=3.exp&sensor=false&libraries=places"></script>
  <script>
var geocoder;
var map;
function initialize() {

var input = document.getElementById('address');
var options = {

componentRestrictions: {country: "in"}
};
var autocomplete = new google.maps.places.Autocomplete(input,options);
geocoder = new google.maps.Geocoder();


//var latlng = new google.maps.LatLng(18.52043030000, 73.85674369999);

var mapOptions = {
 zoom: 15,
//center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,

}

var map = new google.maps.Map(document.getElementById('googleMap'), mapOptions);

}



function codeAddress() {
 var address = document.getElementById('address').value;


 geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {

 map.setCenter(results[0].geometry.location);
  var marker = new google.maps.Marker({
      map: map,
      position: results[0].geometry.location
  });
  } else {
  alert('Geocode was not successful for the following reason: ' + status);
  }
 });
}


 google.maps.event.addDomListener(window, 'load', initialize);
 </script>

It is runnig as expected but it gives error in console "You have included the Google Maps API multiple times on this page. This may cause unexpected errors.". Because of that map doesn't show properties on map.

Kedar B
  • 774
  • 5
  • 18
  • 47

3 Answers3

6

Remove the first line:

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>

You are including the Google Maps API twice.

Mike
  • 8,767
  • 8
  • 49
  • 103
0

Your problem is that, like others have found out, the duplicate script of the Google Maps. Please check the link below for working code.

http://jsbin.com/husahasu/1/edit

To render the map you need to specify its centre. It will not render without it. You also need to add css for your elements. Put this in the head of the document.

<style type="text/css">
 html { height: 100% }
 body { height: 100%; margin: 0; padding: 0 }
 #googleMap { height: 100% }
</style>
  • Please provide your entire code (pastebin.com maybe) –  Aug 05 '14 at 11:51
  • The script in the link is functional, are there any errors in the console? Does the map render? –  Aug 05 '14 at 11:57
  • yes..there are errors.. "You have included the Google Maps API multiple times on this page. This may cause unexpected errors." – Kedar B Aug 05 '14 at 11:58
  • I've checked your script. You need css rules set so that the map div has a height; write the errors; check the above answer. –  Aug 05 '14 at 11:59
0

In my case I inserted link to the library twice, in the top page and before div. I delete any link and it's will work. You check links in your page.