Hi,
Ref:
https://developers.google.com/maps/documentation/geocoding/intro
My request is based on me assuming that your plugin does the following. My excuses if it does not:
1) A user types in an address in the block’s address field.
2) Your code does an API request to Google to get the geocoding info for this address:
https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY
3) You get back a JSON or XML response from Google eg:
{
"results" : [
{
"address_components" : [
{
"long_name" : "1600",
"short_name" : "1600",
"types" : [ "street_number" ]
},
{
"long_name" : "Amphitheatre Pkwy",
"short_name" : "Amphitheatre Pkwy",
"types" : [ "route" ]
},
{
"long_name" : "Mountain View",
"short_name" : "Mountain View",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Santa Clara County",
"short_name" : "Santa Clara County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "94043",
"short_name" : "94043",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
"geometry" : {
"location" : {
"lat" : 37.4224764,
"lng" : -122.0842499
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 37.4238253802915,
"lng" : -122.0829009197085
},
"southwest" : {
"lat" : 37.4211274197085,
"lng" : -122.0855988802915
}
}
},
"place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
4) You take out the lat and long info to then show the map with this location in the edit and front end of the block.
So it is my assumption that you in your code already have all the above info in memory.
By an API I mean eg a function you write that allows developers to get parts of this info eg lat and long, full name, etc. A function I could use in a template or plugin to get the lat and long info for the current or a particular post id:
eg:
maps_block_get_lat (post_id);
The reason for this is that I can then store lat and long in custom fields with the post. I can then do searches for posts located in a certain region by searching for lat and long within a range….
This is a lot of assumption on my part though ??
Another way of doing this would be for you to create custom fields for lat and long for each post and put the lat and long in there so it can be accessed by users…..
Let me know your thoughts….
-
This reply was modified 6 years, 8 months ago by
wpfan1000.