Domanda

I'm trying to add a marker on a building/premise on google maps, to do this I'm using the Geocoding API. I tested it out by requesting an address and it worked perfectly.

var address = "...";
var geocoder = new google.maps.Geocoder();
geocoder.geocode( {'address': address }, function(results, status) {
  if (status == google.maps.GeocoderStatus.OK) {
    var location_marker = new google.maps.Marker({
      map: map,
      position: results[0].geometry.location
    });
  }
});

According to the Geocoding API you can request a building/premise by using the premise property, but when using premise I'm getting a JavaScript error Uncaught InvalidValueError: unknown property premise.

This is how I'm requesting the premise property:

var premise = "...";
var geocoder = new google.maps.Geocoder();
geocoder.geocode( {'premise': premise }, function(results, status) {
  if (status == google.maps.GeocoderStatus.OK) {
    var location_marker = new google.maps.Marker({
      map: map,
      position: results[0].geometry.location
    });
  }
});

I followed the answer given for this question

Not sure if anyone has had this problem before. Maybe there's another way to tackle this as well.

UPDATE

In case someone stumbles upon this question, to search businesses/places on Google Maps you can use the Places Library. This returns objects with the business's address, location, name etc.

Hopefully this helps someone :)

È stato utile?

Soluzione

I there's some confusion here about what the Geocode API does. Read the API again for requests.

The required parameters are address or latlng or components, and sensor.

The optional parameters are bounds, language, region and components.

Premise is one of the properties of the returned JSON data. This means that you can't use it as a search parameter which is why the API is complaining.

The answer in that question to which you linked is wrong.

Hope this is helpful.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top