谷歌地图 - 按城市名称嵌入地图

时间:2016-07-18 20:51:17

标签: javascript html google-maps iframe google-maps-api-3

有没有办法只使用城市名称来嵌入地图,如下面的代码?

FIND_PACKAGE(sphinxbase)
if (${SPHINXBASE_FOUND})
    INCLUDE_DIRECTORIES(${SPHINXBASE_INCLUDE_DIR}/sphinxbase/)
else ()
    ExternalProject_Add(
        sphinxbase
        GIT_REPOSITORY      "https://github.com/cmusphinx/sphinxbase.git"
        SOURCE_DIR          ${CMAKE_CURRENT_SOURCE_DIR}/lib/sphinxbase
        CONFIGURE_COMMAND   ""
        BUILD_COMMAND       msbuild sphinxbase.sln /p:PlatformToolset=v140
        UPDATE_COMMAND      ""
        INSTALL_COMMAND     ""
        BUILD_IN_SOURCE     ON
        LOG_DOWNLOAD        ON
        LOG_UPDATE          ON
        LOG_CONFIGURE       ON
        LOG_BUILD           ON
        LOG_TEST            ON
        LOG_INSTALL         ON
    )
    ExternalProject_Get_Property(sphinxbase SOURCE_DIR)
    ExternalProject_Get_Property(sphinxbase BINARY_DIR)
    SET(SPHINXBASE_SOURCE_DIR ${SOURCE_DIR})
    SET(SPHINXBASE_BINARY_DIR ${BINARY_DIR})
    SET(SPHINXBASE_LIBRARIES ${SPHINXBASE_BINARY_DIR}/bin/Debug/Win32/sphinxbase.dll)
    SET(DEPENDENCIES ${DEPENDENCIES} sphinxbase)
    INCLUDE_DIRECTORIES(${SPHINXBASE_SOURCE_DIR}/include/win32)
    INCLUDE_DIRECTORIES(${SPHINXBASE_SOURCE_DIR}/include)
endif ()
SET(LIBS ${LIBS} ${SPHINXBASE_LIBRARIES})

FIND_PACKAGE(pocketsphinx)
if (${POCKETSPHINX_FOUND})
    INCLUDE_DIRECTORIES(${POCKETSPHINX_INCLUDE_DIR}/pocketsphinx/)
    add_definitions( -DMODELDIR="/usr/local/share/pocketsphinx/model")  # more portable?
else ()
    ExternalProject_Add(
        pocketsphinx
        DEPENDS             sphinxbase
        GIT_REPOSITORY      "https://github.com/cmusphinx/pocketsphinx.git"
        SOURCE_DIR          ${CMAKE_CURRENT_SOURCE_DIR}/lib/pocketsphinx
        CONFIGURE_COMMAND   ""
        BUILD_COMMAND       msbuild pocketsphinx.sln /p:PlatformToolset=v140
        UPDATE_COMMAND      ""
        INSTALL_COMMAND     ""
        BUILD_IN_SOURCE     ON
        LOG_DOWNLOAD        ON
        LOG_UPDATE          ON
        LOG_CONFIGURE       ON
        LOG_BUILD           ON
        LOG_TEST            ON
        LOG_INSTALL         ON
        )
    ExternalProject_Get_Property(pocketsphinx SOURCE_DIR)
    ExternalProject_Get_Property(pocketsphinx BINARY_DIR)
    SET(POCKETSPHINX_SOURCE_DIR ${SOURCE_DIR})
    SET(POCKETSPHINX_BINARY_DIR ${BINARY_DIR})
    SET(POCKETSPHINX_LIBRARIES ${POCKETSPHINX_BINARY_DIR}/bin/Debug/Win32/pocketsphinx.dll)
    SET(DEPENDENCIES ${DEPENDENCIES} pocketsphinx)
    INCLUDE_DIRECTORIES(${POCKETSPHINX_SOURCE_DIR}/include/)
    add_definitions(-DMODELDIR="${POCKETSPHINX_BINARY_DIR}/model")
endif ()
SET(LIBS ${LIBS} ${POCKETSPHINX_LIBRARIES})

FIND_PACKAGE(PortAudio)
if (${PORTAUDIO_FOUND})
    INCLUDE_DIRECTORIES(${PORTAUDIO_INCLUDE_DIRS})
else ()
    ExternalProject_Add(
        PortAudio
        GIT_REPOSITORY      "https://github.com/syb0rg/PortAudio2.git"
        SOURCE_DIR          ${CMAKE_CURRENT_SOURCE_DIR}/lib/PortAudio
        UPDATE_COMMAND      ""
        INSTALL_COMMAND     ""
        BUILD_IN_SOURCE     ON
        LOG_DOWNLOAD        ON
        LOG_UPDATE          ON
        LOG_CONFIGURE       ON
        LOG_BUILD           ON
        LOG_TEST            ON
        LOG_INSTALL         ON
    )
    ExternalProject_Get_Property(PortAudio SOURCE_DIR)
    ExternalProject_Get_Property(PortAudio BINARY_DIR)
    SET(PORTAUDIO_SOURCE_DIR ${SOURCE_DIR})
    SET(PORTAUDIO_BINARY_DIR ${BINARY_DIR})
    SET(PORTAUDIO_LIBRARIES ${PORTAUDIO_BINARY_DIR}/libportaudio_x86.dll)
    SET(DEPENDENCIES ${DEPENDENCIES} PortAudio)
    INCLUDE_DIRECTORIES(${PORTAUDIO_SOURCE_DIR}/include)
endif ()
SET(LIBS ${LIBS} ${PORTAUDIO_LIBRARIES})

FIND_PACKAGE(LibSndFile)
if(${LIBSNDFILE_FOUND})
    INCLUDE_DIRECTORIES(${LIBSNDFILE_INCLUDE_DIRS})
else ()
    ExternalProject_Add(
        LibSndFile
        GIT_REPOSITORY      "https://github.com/syb0rg/libsndfile.git"
        SOURCE_DIR          ${CMAKE_CURRENT_SOURCE_DIR}/lib/LibSndFile
        UPDATE_COMMAND      ""
        INSTALL_COMMAND     ""
        BUILD_IN_SOURCE     ON
        LOG_DOWNLOAD        ON
        LOG_UPDATE          ON
        LOG_CONFIGURE       ON
        LOG_BUILD           ON
        LOG_TEST            ON
        LOG_INSTALL         ON
    )
    ExternalProject_Get_Property(LibSndFile SOURCE_DIR)
    ExternalProject_Get_Property(LibSndFile BINARY_DIR)
    SET(LIBSNDFILE_SOURCE_DIR ${SOURCE_DIR}/src)
    SET(LIBSNDFILE_BINARY_DIR ${BINARY_DIR})
    SET(LIBSNDFILE_LIBRARIES ${LIBSNDFILE_BINARY_DIR}/libsndfile.dll)
    SET(DEPENDENCIES ${DEPENDENCIES} LibSndFile)
    INCLUDE_DIRECTORIES(${LIBSNDFILE_SOURCE_DIR})
endif ()
SET(LIBS ${LIBS} ${LIBSNDFILE_LIBRARIES})

FIND_PACKAGE(tritium)
if (${TRITIUM_FOUND})
    INCLUDE_DIRECTORIES(${TRITIUM_INCLUDE_DIR}/)
else ()
    ExternalProject_Add(
        tritium
        GIT_REPOSITORY  "https://github.com/syb0rg/tritium.git"
        SOURCE_DIR      ${CMAKE_CURRENT_SOURCE_DIR}/lib/tritium
        UPDATE_COMMAND  ""
        INSTALL_COMMAND ""
        BUILD_IN_SOURCE ON
        LOG_DOWNLOAD    ON
        LOG_UPDATE      ON
        LOG_CONFIGURE   ON
        LOG_BUILD       ON
        LOG_TEST        ON
        LOG_INSTALL     ON
    )
    ExternalProject_Get_Property(tritium SOURCE_DIR)
    ExternalProject_Get_Property(tritium BINARY_DIR)
    SET(TRITIUM_SOURCE_DIR ${SOURCE_DIR})
    SET(TRITIUM_BINARY_DIR ${BINARY_DIR})
    SET(TRITIUM_LIBRARIES ${TRITIUM_BINARY_DIR}/libtritium.a)
    SET(DEPENDENCIES ${DEPENDENCIES} tritium)
    INCLUDE_DIRECTORIES(${TRITIUM_SOURCE_DIR}/include)
endif ()
SET(LIBS ${LIBS} ${TRITIUM_LIBRARIES})

2 个答案:

答案 0 :(得分:1)

请参阅Embed API的文档。

  

放置模式

     

地方模式会在特定地点或地址显示地图图钉,例如地标,商家,地理特征或城镇。

     

https://www.google.com/maps/embed/v1/place     ?关键= YOUR_API_KEY     &安培; Q =艾菲尔+铁塔,巴黎+法国

     

需要以下网址参数:

     
      
  • q定义要在地图上突出显示的位置。它接受一个位置作为地名,地址或地点ID。字符串应该是URL转义的,因此诸如“City Hall,New York,NY”的地址应该转换为City + Hall,New + York,NY。 (Google地图嵌入API在转义空格时支持+和%20。)地点ID应以place_id为前缀:。
  •   

法国巴黎的例子:

<iframe width="100%" height="600" frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/place?q=Paris, France&amp;key=YOUR_API_KEY">
</iframe>

working example

答案 1 :(得分:0)

你可以使用javascript或jQuery for google map api点击事件,如此...

                     $('...ELEMENT, CLASS, BUTTON....').click(function(){
                        $.ajax({
                            type:"GET",
                            url:"https://maps.googleapis.com/maps/api/geocode/xml?address=...CITY NAME...&key=...YOUR KEY GOES ERE...",
                            dataType:'xml',
                            success: function(xml){

                                    }
                                });
                            }
                        });
                    });

如果你喜欢,你可以使用JSON

或者如果你不想点击和ajax功能只需复制n粘贴你的url和城市名称的网址

您可以从此处创建密钥:     https://console.developers.google.com/flows/enableapi?apiid=maps_backend,geocoding_backend,directions_backend,distance_matrix_backend,elevation_backend,places_backend&keyType=CLIENT_SIDE&reusekey=true&pli=1

希望这会有所帮助。