google maps on rails

http://www.killswitchcollective.com/articles/65_google_maps_on_rails

The Google Maps API is without a doubt one of the most popular APIs available on the web today. It offers webmasters the ability to add mapping functionality, similar to maps.google.com, to their websites. All of Google Maps functionalities, including markers, directions, zoom options and satellite view are only a few lines of code away. But before we get started with the code portion, you will need a Google Maps API key. Getting a Google Maps API key takes a minute and costs nothing. Just sign in to your Google Account (I am sure you have one) and head to http://code.google.com/apis/maps. On the right hand side you will see ‚How Do I Start, where you will just simply click on Step 1 "Sign up for a Google Maps API key". Then enter your site's live domain, accept the terms and click the "Generate API Key" button. On the next page your unique API key will appear. Make sure that you copy and paste it to a safe location. Below the API key will be JavaScript examples to quickly get you started. In this tutorial, we will generate similar code with the use of some rails plug-ins. The most popular plug-in is the Yellow Maps for Ruby, also known as YM4R. Since there are other mapping APIs, this plug-in comes in a few flavors. Since we're doing Google Maps, we will use YM4R/GM.

1. Lets start by generating a new Rails application:

rails map_example -d mysql

2. Create a 'map_example_development' database and remove index.html from the public folder

cd map_example
rake db:create

rm public/index.html


3. The lets add a controller and the index action

script/generate controller location index

4. Lets install the YM4R/GM plugin

script/plugin install git://github.com/queso/ym4r-gm.git

5. Add frontend.html.erb in app/views/layouts with the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Google Maps Rails Example</title>

<%= GMap.header %>
<%= @map.to_html unless @map.blank? %>
</head>
<body>

<%= yield %>

</body>
</html>

====
Note that we have included two YM4R/GM lines in the head section. The GMap.header will include needed JavaScript files while the @map.to_html line generates JavaScript based on the parameters passed into the map object. We will be creating the @map object in our location controller.

6. Don't forget to specify the layout in /app/controllers/location_controller:

class LocationController < ApplicationController
layout 'frontend'
def index
coordinates = [23.11374751041939, 113.39768183810425]

@map = GMap.new("map")
@map.control_init(:large_map => true, :map_type => true)
@map.center_zoom_init(coordinates,14)
@map.overlay_init(GMarker.new(coordinates,:title => "Navy Pier", :info_window => "Navy Pier"))
end

end

---
First we set our map coordinates into an array. The first number is the latitude and second is the longitude. These coordinates point to Navy Pier in Chicago, Illinois. If you would like to try a different area for this example, this easy tool (http://stevemorse.org/jcal/latlon.php) provides you the latitude and longitude for any address you want to use.. Next, we set the @map object to pass into our view. The @map object contains a new instance of the GMap class; the "map" string is the id of the div that will contain the map. The next line activates controls for our map. The large map activates the zoom option while the map type activates various views such as a regular map, satellite or terrain. Then we set the default map center and zoom. We first pass in the coordinates array so our location will be centered, then we pass in a integer to determine zoom level. This integer can be between 0 and 22, the higher the number the more the zoomed in the map will be. Finally, we add a marker overlay. The first argument is the coordinates and it is the only required argument need to add a marker. The title and info_window are both optional, title is the text that will display when your mouse is idle over the marker, while info_window is the text that will appear in the pop up box that appears after clicking the marker.
--
8. Next open our view file located at app/views/location/index.html.erb and add the following:

<h1>Google Maps Rails Example</h1>

<%= @map.div(:width => 800, :height => 500) %>

9. Map the homepage to the index action of location by adding the following to config/routes.rb.

map.root :controller => "location", :action => "index"

10. Fire up your rails application and a map should appear.

...
1、利用 Google Maps API 和 Ruby on Rails 构建强大地图应用 本文介绍了如何结合 Google Maps API 和 Ruby on Rails 构建强大的网页地图应用。从使用 KML 文件和第三方工具 Wayfaring 快速创建地图入手,逐步深入讲解了 Rails 应用的搭建、地图集成、用户交互功能实现以及与服务器的通信和地理编码等关键技术点。旨在帮助开发者快速掌握地图应用开发的核心技能,并为构建更复杂的应用打下坚实基础。 阅读详情

相关推荐

fibplus-8.0.0.zip

FIBPlus 是一套面向 Delphi / C++Builder 的 Firebird、InterBase 数据库访问组件,特点是直接走原生客户端 API,不经 BDE/ODBC,速度快且可控性强。8.0.0 版本主要适配 Delphi 2009 及以后的版本(Delphi 6–2007 需用 7.9.x),核心组件包括 TpFIBDatabase、TpFIBTransaction、TpFIBDataSet 等,支持精细事务管理、本地缓存、BLOB 处理和备份恢复等数据库服务。该库原为 Devrace 的商业组件,现由社区在 GitHub 的 madorin/fibplus 项目开源维护,建议从官方仓库获取源码而非第三方网盘压缩包。安装时解压后用对应版本的工程组(10.4+ 统一为 `FIB.groupproj`)Build 全部包,再 Install `dclFIB` 并在 Library 路径加入 Source 目录即可。新项目中若需官方技术支持,也可考虑 FireDAC、IBDAC 等更现代的替代方案。

Google Maps on Rails

  https://github.com/YouthTree/bhm-google-maps   https://github.com/joshuamiller/cartographer   https://github.com/skozlov/netzke-communitypack   https://github.com/apneadiving/Google-Maps-for-...

whz110的专栏 107

ROS智能车定位导航仿真+功能包自带的地图实现+自己建立的地图实现

ROS智能车定位导航仿真一、前言二、效果图三、准备工作[1.在Ubuntu上安装ROS Kinetic](https://blog.youkuaiyun.com/qq_42585108/article/details/104327661)2.创建ROS工作区间①1创建racecar_ws和src文件夹②初始化工作空间③下载racecar源代码包,并编译工程四、启动仿真1.设置环境变量2.启动地图五、建图1.启动slam和rviz2 控制车辆(左侧有个控制窗口),WASD控制前左后右的运动就可以建图了:3.新建终端保存地

qq_42585108的博客 1万+

Google-Maps-for-Rails核心功能解析:标记、信息窗口与多边形实现

Google-Maps-for-Rails是一款为Ruby应用提供便捷Google地图集成的工具,能够轻松实现地图标记、信息窗口和多边形等核心功能。本文将详细介绍如何利用这个强大的gem快速构建交互式地图应用。 ## 快速上手:Google-Maps-for-Rails基础配置 要开始使用Google-Maps-for-Rails,首先需要在Gemfile中添加依赖: ```ruby gem

gitblog_00426的博客 887

新手DIY无人机,从电机到飞控,这份配件清单和避坑指南请收好

本文为无人机DIY新手提供从电机到飞控的完整配件清单和避坑指南。详细解析电机KV值选择、电调匹配、飞控系统调试等核心问题,帮助初学者避开常见雷区,顺利完成首飞。特别推荐FPV竞速机和航拍机的配件组合方案,并附赠实用调试命令和故障排查表。

weixin_27032989的博客 236

解决windows10下无法安装.net framework 3.5(包括.net2.0和3.0)

入域电脑,win10系统中安装 .net framework 3.5(包括.net2.0和3.0)

God_me_1的博客 4万+

Ruby on Rails Web Mashup Projects

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.youkuaiyun.com/topmvp - topmvpA web mashup is a new type of web application that uses data and services from one or more external sources t

TopMVP 630

UVM自学笔记3——项目之三——从零开始搭建ahb_sramc验证平台

创建如下所示的目录结构: 2.在tb的文件下:顶层的testbench如下:在tb中,第24行的代码将uvm宏相关的内容include进来,第26行的代码把uvm_pkg包导入进来,然后将agent相关的包(ahb_pkg/sram_pkg),testcase相关的包(uvm_ahb_sram_test_pkg)以及env相关的包(uvm_ahb_sram_env_pkg)都导入进来,在第38行和39行将接口以virtual interface的形式配置给ahb_agent和sramc_agent下

ZhangShuHuai11的博客 9474

Rails 當中使用 Google Map:YM4R

最近發現 Google Map 很好玩,想要玩玩 Ruby on Rails 上面的 Google Map,就找上了 YM4R 這個 Rails Plugin,發現 YM4R 使用 Google Map真是方便呀,彈指之間搞定。YM4R 這個 Plugin 就是讓Ruby on Rails 上面使用 Yahoo Map 跟 Google Map 的 Rails Plugin。以下介紹一下這個 YM...

thegiive 184

基于STM32F407标准库与SimpleFOC实现无刷电机2804位置闭环控制的实战解析

本文详细解析了基于STM32F407标准库与SimpleFOC算法实现2804无刷电机位置闭环控制的实战过程。通过硬件选型、速度闭环调试到位置环PID参数整定,提供了完整的工程实现方案和抗饱和策略,帮助开发者掌握高精度电机控制技术。

oauth7security的博客 917

计算蛋白质结构中氨基酸之间的方向和方位

方向 (Direction):通过相邻氨基酸的 CαCα​ 原子坐标差值,得到方向向量,描述两个氨基酸之间的几何方向。方位 (Orientation):可以通过二面角(如 Psi)来表示相邻氨基酸之间的旋转关系,或者通过局部坐标系(基于 NN、CαCα​、CC 原子)描述残基的空间取向。这些计算是研究蛋白质结构动力学、折叠过程、以及相互作用的基础,尤其是在使用机器学习和深度学习模型进行蛋白质结构预测时,这些几何信息有助于更好地捕捉残基之间的空间关系。

qq_27390023的博客 1679

【软件系统架构】系列十一:面向对象技术—sysML

摘要: SysML(系统建模语言)是UML的扩展,专为复杂系统工程设计,支持硬件、软件、人员等跨领域建模。其核心包括9种图:4种结构图(如块定义图BDD、内部块图IBD)、4种行为图(如活动图AD、序列图SD)和需求图(REQ),覆盖需求、结构、行为及参数约束。相比UML(面向软件),SysML精简图表(9 vs 13),强化需求追踪与性能分析(如参数图PD),并支持MBSE(基于模型的系统工程)。需求关系(如满足、验证、派生)在需求图中明确关联设计实现,形成闭环管理。SysML是UML的子集与系统工程扩展

moton2017的博客 1905

Cartographer

Cartographer Ruby on Rails :: Google Maps plugin Installation Install as a plugin! From your rails application root, run script/plugin install -x svn://cartographer.rubyforge.org/trunk/vend...

weixin_30549657的博客 80

24年电赛H题 | 想要小车走直线,正在调角度环,但不知道怎么把角度偏航角偏差转化成电机速度输出?

🏆本文收录于 《全栈 Bug 调优(实战版)》 专栏。专栏聚焦真实项目中的各类疑难 Bug,从成因剖析 → 排查路径 → 解决方案 → 预防优化全链路拆解,形成一套可复用、可沉淀的实战知识体系。无论你是初入职场的开发者,还是负责复杂项目的资深工程师,都可以在这里构建一套属于自己的「问题诊断与性能调优」方法论,助你稳步进阶、放大技术价值 。

**My Coding Family** 1313

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

ROR与社区网站开发

Ruby on Rails社区网站开发“这是一部杰作!有它在手,足以开发出一个真正的社区网站。书中采用了模块化的方法,实例可以非常容易地复用,比如在现有网站中添加社区网络功能。”——David Berube,资深Ruby技术专家,Practical Ruby Gems一书作者 “我非常喜欢这本书,相信所有RoR程序员都会从中获益匪浅。”——Larry Wright,资深RoR和

图灵教育 1682

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Google-Maps-for-Rails企业级应用案例:打造高并发地图服务

Google-Maps-for-Rails是一款专为Ruby应用设计的地图集成工具,能够轻松实现Google地图及覆盖层功能。本文将通过企业级应用案例,分享如何利用该工具构建高性能、高并发的地图服务,帮助开发者快速掌握核心技术要点。 ## 🌟 企业级地图服务的核心挑战 在大规模应用中,地图服务面临三大核心挑战:数据处理效率、并发请求响应速度和前端渲染性能。Google-Maps-for-Ra

gitblog_00690的博客 803

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

在Rails中使用Google Maps

地图是导航世界的方式。 他们给检查地球上的每一个位置,开辟了道路服务,如路由和土壤成分的能力。 在这篇文章中,我将通过谷歌地图API(和一些替代品),并使用Rails集成。 教程源库 该源代码可在Github上库 。 每个功能都是单独提交,这样你就可以使用按照教学进度git checkout 。 先决条件 在使用Rails的Ruby的基本知识RailsBricks 。 JavaScr...

473

Beginning Google Maps Applications with Rails and Ajax: From Novice to Professional

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.youkuaiyun.com/topmvp - topmvpThe Google Maps API remains one of the showcase examples of the Web 2.0 development paradigm. Beginning Googl

TopMVP 456

rails pry使用_在Rails中使用Google Maps

rails pry使用 地图是导航世界的方式。 他们具有检查地球上每个位置的能力,从而为路线和土壤成分等服务开辟了道路。 在本文中,我将介绍Google Maps API(和一些替代方法)并将其与Rails集成。 教程源存储库 源代码可从Github存储库中获得 。 每个功能都是一个单独的提交,因此您可以使用git checkout跟随教程的进度。 先决条件 使用RailsBri...

561

The Use of Google-Maps-for-Rails

http://caok.github.com/blog/2012/08/19/the-use-of-google-maps-for-rails/   这个我前两天写的对个google maps for rails的使用的一个简单说明,之后也对里面的一些实用的东西进行补充。...

zimo1231的专栏 164

Google Data On Rails

Monday, February 23, 2009 at 9:04 AM Posted by Eric Bidelman, Google Data APIs Team"Where's Ruby on the list of&nbsp;client libraries?"My colleague Jeff Fisher recently open sourced a&nbsp;Ruby uti...

hooopo的专栏 198

rails recipes_Google Maps Recipes入门

rails recipes 有多种方法可以将Google Map添加到网页。 Google提供了多种地图类型,其用途基本上取决于您的需求。 在不考虑某些特定用途的情况下(例如, 地方或地球的 API),最常用的地图类型为: 静态地图和街景图像 嵌入式地图 JavaScript地图 还有许多Web服务可改善地图,以及用于移动设备的特定API。 在本文中,我们将仅介绍网页的基本...

121

gmap4rails

https://github.com/thasuresh/gmaps_projecthttp://thasulinux.wordpress.com/2011/05/10/google-maps-in-rails3-application-sample-application/https://github.com/apneadiving/Google-Maps-for-Railshttp://tru...

weixin_33762130的博客 70

Rails中使用geometry格式的数据

我只是给自己看的= =转载自: http://climber2002.github.io/blog/2014/05/26/integrate-postgis-and-google-maps-in-rails-part-2/

OldRoy的专栏 414
上一篇: Command line mp3 player in Linux
下一篇: 网页爬虫程序开发经验谈 <转>
wavee
博客等级 码龄22年 0粉丝 40原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值