Hector Hernandez
Hector Hernandez

Reputation: 155

How to get a specific place in rails with Google Maps

I have been trying to get a specific place in Rails with Google Maps, because when I try to get a restaurant, an university, I can't get! I only get the city, or the state, maybe the street, but not the place.

view:

<div style='width: 100%;' class="border">
  <div id="map" style='width: 100%; height: 260px;'></div>
</div>

<script src="//maps.google.com/maps/api/js?key=AIzaSyAqkiGaIZh9q6DPUabw9E1rEqIQ-9X5amI"></script>
    <script src="//cdn.rawgit.com/mahnunchik/markerclustererplus/master/dist/markerclusterer.min.js"></script>
    <script src='//cdn.rawgit.com/printercu/google-maps-utility-library-v3-read-only/master/infobox/src/infobox_packed.js' type='text/javascript'></script> <!-- only if you need custom infoboxes -->

    <script type="text/javascript">
    handler = Gmaps.build('Google');
    handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
    markers = handler.addMarkers(<%= raw @hash.to_json %>);
    handler.bounds.extendWith(markers);
    handler.fitMapToBounds();
    handler.getMap().setZoom(15);
    });
    </script>

Controller, action show:

def show
   @enterprise = Enterprise.find(params[:id])
   @hash = Gmaps4rails.build_markers(@enterprise) do |enterprise, marker|
    marker.lat enterprise.latitude
    marker.lng enterprise.longitude
  end
end

Upvotes: 0

Views: 600

Answers (3)

Milind
Milind

Reputation: 5112

i assume you need to be more specific while querying to google map...

so while using Google Places api..every PlaceResult object can query from various parameters...what you need is to specify types parameter too.

Copy and pasting from the above url...

types An array of types for this place (e.g., ["political", "locality"] or ["restaurant", "lodging"]).

Give it a try.. :)

Upvotes: 0

Hector Hernandez
Hector Hernandez

Reputation: 155

Apparently I need to add something like this in my app, I think in my javascript code, but I don't get any change

"results" : [
    {
      "place_id" : "MY_KEY_API",
      "scope" : "GOOGLE",
      "alt_ids" : [
        {
          "place_id" : "MY_KEY_API",
          "scope" : "APP",
        }
      ]

Upvotes: 1

Michael Malov
Michael Malov

Reputation: 1887

You need to provide coordinates more accurate. Check enterprice latitude and longitude.

For example, not accurate will be

enterprise.latitude
# => 41
enterprise.longitude
# => -87

And accurate one are

enterprise.latitude
# => 41.850033
enterprise.longitude
# => -87.6500523

Upvotes: 0

Related Questions