# Geocoder for Sketchup ruby API

**URL:** <https://forums.sketchup.com/t/geocoder-for-sketchup-ruby-api/21253>\
**Category:** Ruby API\
**Tags:** sketchup, geolocation\
**Created:** [February 29, 2016, 2:29pm UTC](https://forums.sketchup.com/t/geocoder-for-sketchup-ruby-api/21253 "2016-02-29T14:29:11Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![MR\_ME](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@MR\_ME](https://forums.sketchup.com/u/MR_ME)\
**Post date:** [February 29, 2016, 2:29pm UTC](https://forums.sketchup.com/t/geocoder-for-sketchup-ruby-api/21253/1 "2016-02-29T14:29:12Z")

</div>

hello everyone,

I’m trying to create a model of a house that exists in real life, and add an inputbox where the user can write the actual address of that house and then show location of that building in Google Maps.

i tried to install geocoder: Gem.install(“geocoder”)

but it doesn’t find it:

```
Code: Select allGem.install("geocoder")
Error: #<Gem::SpecificGemNotFoundException: Could not find a valid gem 'geocoder' (>= 0) locally or in a repository>
C:/Program Files/SketchUp/SketchUp 2016/Tools/RubyStdLib/rubygems/dependency_installer.rb:301:in `find_spec_by_name_and_version'
C:/Program Files/SketchUp/SketchUp 2016/Tools/RubyStdLib/rubygems/dependency_installer.rb:110:in `available_set_for'
C:/Program Files/SketchUp/SketchUp 2016/Tools/RubyStdLib/rubygems/dependency_installer.rb:322:in `install'
C:/Program Files/SketchUp/SketchUp 2016/Tools/RubyStdLib/rubygems.rb:526:in `install'
<main>:in `<main>'
SketchUp:1:in `eval'

```

does this gem works only for Ruby on Rails and Sinatra … ? is there another gem like geocoder that is used for the Ruby Sketchup API ?

thank you a lot.

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [February 29, 2016, 2:58pm UTC](https://forums.sketchup.com/t/geocoder-for-sketchup-ruby-api/21253/2 "2016-02-29T14:58:47Z")

</div>

Try

`Gem::install("geocoder")`

It worked for me…

---

<div class="post-metadata">

**Author:** ![MR\_ME](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@MR\_ME](https://forums.sketchup.com/u/MR_ME)\
**Post date:** [February 29, 2016, 3:02pm UTC](https://forums.sketchup.com/t/geocoder-for-sketchup-ruby-api/21253/3 "2016-02-29T15:02:02Z")

</div>

it worked thnx 🙂

does this gem provide the possibility to generate a google map in a popup window containing the location based on a the address and street … given ?

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [February 29, 2016, 3:08pm UTC](https://forums.sketchup.com/t/geocoder-for-sketchup-ruby-api/21253/4 "2016-02-29T15:08:10Z")

</div>

‘Get Location’ already does that…

what are you trying to do that’s different?

 ![](https://global.discourse-cdn.com/sketchup/original/2X/e/e4bd8e28cc243b722a16c72e4cf6a9e88c9f6601.gif)

or if you want to open in the users browser not SU…

```ruby
UI.openURL("https://www.google.com/maps/place/The+British+Museum")

```

you need to escape an address, but it works from Ruby Console or a plugin…

john

---

<div class="post-metadata">

**Author:** ![MR\_ME](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@MR\_ME](https://forums.sketchup.com/u/MR_ME)\
**Post date:** [February 29, 2016, 5:21pm UTC](https://forums.sketchup.com/t/geocoder-for-sketchup-ruby-api/21253/5 "2016-02-29T17:21:23Z")

</div>

thank you so much for your answer 🙂  
`UI.openURL("https://www.google.com/maps/place/The+British+Museum")`  
responds exactly to what i want

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [February 29, 2016, 5:37pm UTC](https://forums.sketchup.com/t/geocoder-for-sketchup-ruby-api/21253/6 "2016-02-29T17:37:37Z")

</div>

did you try any address’s?  
you don’t even need the country or html escape, it just needs spaces replaced with a plus…

`gsub('/ */, '+')`

```ruby
UI.openURL("https://www.google.com/maps/place/123+Toongarra+Rd,+Wulkuraka+QLD+4305")

```

I do a similar thing with Google Translate…

john

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [February 29, 2016, 10:57pm UTC](https://forums.sketchup.com/t/geocoder-for-sketchup-ruby-api/21253/7 "2016-02-29T22:57:10Z")

</div>

(_Moved to **Ruby API** category._)

Also see this thread:  
[**Is there anyway to open the Geo-location-\>Add location dialog by ruby?**](http://forums.sketchup.com/t/is-there-anyway-to-open-the-geo-location-add-location-dialog-by-ruby/17028)

---

<div class="post-metadata">

**Author:** ![MR\_ME](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@MR\_ME](https://forums.sketchup.com/u/MR_ME)\
**Post date:** [March 1, 2016, 9:25am UTC](https://forums.sketchup.com/t/geocoder-for-sketchup-ruby-api/21253/8 "2016-03-01T09:25:20Z")

</div>

yeah i tried some addresses but instead of /place/ i used /search/ so it adds the “+” by itself and generates the /place/ with “+”  
`UI.openURL("https://www.google.com/maps/search/123 Toongarra Rd, Wulkuraka QLD 4305")`

---

<div class="post-metadata">

**Author:** ![MR\_ME](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@MR\_ME](https://forums.sketchup.com/u/MR_ME)\
**Post date:** [March 1, 2016, 11:10am UTC](https://forums.sketchup.com/t/geocoder-for-sketchup-ruby-api/21253/9 "2016-03-01T11:10:58Z")

</div>

the code:

```
GEOLOCATION_ADD_DIALOG = 24216

Sketchup::send_action(GEOLOCATION_ADD_DIALOG)

```

opens a popup an i need to write the address.  
how can i open that popup with location of the house, that i take from an address ?

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [March 1, 2016, 5:03pm UTC](https://forums.sketchup.com/t/geocoder-for-sketchup-ruby-api/21253/10 "2016-03-01T17:03:48Z")

</div>

It would be really helpful if you explained exactly what your trying to do…

and why using ‘Get Location’ isn’t acceptable…

you can duplicate it’s functionality, but I can’t see why you need to…

you trigger it from a plugin…

```ruby
# may differ on PC
Sketchup::send_action('importFromGoogleEarth:')

```

john

---

<div class="post-metadata">

**Author:** ![MR\_ME](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@MR\_ME](https://forums.sketchup.com/u/MR_ME)\
**Post date:** [March 1, 2016, 5:07pm UTC](https://forums.sketchup.com/t/geocoder-for-sketchup-ruby-api/21253/11 "2016-03-01T17:07:17Z")

</div>

thnx for your answer  
i was trying to clique on menu and get a popup with the location of the house on a map based on the address given by the user.  
i solved it using this code:

```
dlg = UI::WebDialog.new("Show location", true,
   "ShowSketchupDotCom", 739, 641, 150, 70, true);
 dlg.set_url "https://www.google.com/maps/search/The+British+Museum"
 dlg.show

```

it shows a popup containing the location of the house based on the address

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [March 1, 2016, 5:23pm UTC](https://forums.sketchup.com/t/geocoder-for-sketchup-ruby-api/21253/12 "2016-03-01T17:23:25Z")

</div>

try this then…

```ruby
dlg = UI::WebDialog.new("Show location", true, "ShowSketchupDotCom", 739, 641, 150, 70, true)
result = UI.inputbox(["Address"])
if result[0] != "" 
  reply = "http://www.google.com/maps/search/" + result[0].gsub(/\s/, '+')
end
 dlg.set_url(reply)
 dlg.show

```

---

<div class="post-metadata">

**Author:** ![MR\_ME](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@MR\_ME](https://forums.sketchup.com/u/MR_ME)\
**Post date:** [March 1, 2016, 5:26pm UTC](https://forums.sketchup.com/t/geocoder-for-sketchup-ruby-api/21253/13 "2016-03-01T17:26:35Z")

</div>

awsome thnx 🙂
